Question about piping

Hi all,
I know this is maybe a newbie type of question, but I just don’t know
what I am doing.
I have numerous directories that may or may not have object files in
them, that I want to delete. However I’m never sure when more
directories might be added.

I figured out how to get find to print me a list of all the names of the
files by doing the following.
find /home -name “*.o” -printf "%h/%f "

But my question is, how can I send this output to rm so that I can
delete all these files?

Currently I have a hack which is doing this
find /home -name “*.o” -printf “rm -f %h/%f \n” > rm.sh

then running that script, it works, but even I know that’s just not
right.

How can I go about sending the files directly to rm to be deleted?

Thanks in advance,


Chris Nasr
cnasr[at]mechtronix[dot]ca
R&D Programming
Mechtronix Systems Inc.

Chris Nasr <cnasr@mechtronix.ca> wrote:

Hi all,
I know this is maybe a newbie type of question, but I just don’t know
what I am doing.
I have numerous directories that may or may not have object files in
them, that I want to delete. However I’m never sure when more
directories might be added.

I figured out how to get find to print me a list of all the names of the
files by doing the following.
find /home -name “*.o” -printf "%h/%f "

But my question is, how can I send this output to rm so that I can
delete all these files?

Currently I have a hack which is doing this
find /home -name “*.o” -printf “rm -f %h/%f \n” > rm.sh

then running that script, it works, but even I know that’s just not
right.

find /home -name “*.o” -remove!

The All Powerful Find is your friend…

If you wanted to do something else, like an interactive remove:

find /home -name “*.o” | xargs rm -i

Cheers,
-RK


Thanks in advance,


Chris Nasr
cnasr[at]mechtronix[dot]ca
R&D Programming
Mechtronix Systems Inc.


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Chris Nasr <cnasr@mechtronix.ca> wrote:

Hi all,
I know this is maybe a newbie type of question, but I just don’t know
what I am doing.
I have numerous directories that may or may not have object files in
them, that I want to delete. However I’m never sure when more
directories might be added.

I figured out how to get find to print me a list of all the names of the
files by doing the following.
find /home -name “*.o” -printf "%h/%f "

But my question is, how can I send this output to rm so that I can
delete all these files?

Currently I have a hack which is doing this
find /home -name “*.o” -printf “rm -f %h/%f \n” > rm.sh

then running that script, it works, but even I know that’s just not
right.

How can I go about sending the files directly to rm to be deleted?

Thanks in advance,

I wouldn’t call it a hack at all. It’s UNIX baby! I have many find
scripts.

Find has a remove option, i.e. ‘-!remove’. So you can change your script
to:
find /home -name “*.o” -printf "%h/%f " -!remove

When you have enough confidence that this is doing what you want you
could just remove the -printf expression.

I would add one more expression too. Only process files, not
directories. I.E.
find /home -type d -name “*.o” -printf "%h/%f " -!remove

If you use this, put it in front of the -name expression and it might
save you some CPU cycles. After the -name it only serves as
documentation (unless some day you have a directory name that ends with
‘.o’.


Bill Caroselli – Q-TPS Consulting
1-(626) 824-7983
qtps@earthlink.net

and now I feel silly, should have looked a little harded at that usage for
find.
Thanks alot Robert and Bill


Chris Nasr
cnasr[at]mechtronix[dot]ca
R&D Programming
Mechtronix Systems Inc.

On Tue, 18 Feb 2003 15:04:46 -0500, Chris Nasr <cnasr@mechtronix.ca> wrote:

and now I feel silly, should have looked a little harded at that usage for
find.
Thanks alot Robert and Bill

Sometime I think you can look at the docs of find all you like
and still not be able to figure just what the hell it does!
These examples ar useful indeed.

acellarius@yahoo.com wrote:

On Tue, 18 Feb 2003 15:04:46 -0500, Chris Nasr <> cnasr@mechtronix.ca> > wrote:
and now I feel silly, should have looked a little harded at that usage for
find.
Thanks alot Robert and Bill

Sometime I think you can look at the docs of find all you like
and still not be able to figure just what the hell it does!
These examples ar useful indeed.

Agreed. Also, it can still be tricky to know which docs to look in.

I was very familiar with the QNX4 docs and it never took me more than
a few minutes to look up alomst anything. But I still have a hard time
finding things that I know are in the currect docs.

Personally, I think the QNX4 helpviewer search worked better than the
QNX6 version does.

(Getting even further off topic)

I just finished writing a script (tin_search) that I use to search
through my local copies of news articles. I can look for articles in
any newsgroups that contain (or don’t contain) several different peices
of text, in any order. I may just modify these to roam through the
helpfiles with a similiar goal. It ain’t fast, but it is good.

I.E. Find articles that mention “this” and “that” but not “something
else”. (Oh yeah. Since it uses grep it won’t find phrases that span
text lines.)