Have a look at the command 'find' using the command:
man find | pg
There are some examples in the man page that will do almost exactly what you want. Mike
________________________________________________________________
"Experience is the comb that Nature gives us, after we are bald."
Is that a haiku?
I never could get the hang
of writing those things.
Is there a reason you prefer xargs to find's own -exec rm {} \; ?
I use xargs for trickier things (like doing a grep on all the XML files in the subdirectories of /usr/local). But for a simple delete, wouldn't -exec rm {} \; do the trick?
Help me out of my ignorance here. Einstein47 ("For every expert, there is an equal and opposite expert." - Arthur C. Clarke)
Hi,
thanks for the response y'all.
The "find $dirs -type f -name "logfile.log" -atime +5
-print|xargs rm"command did it.
But i have a question for Ed.
I don't quit get the "dirs=$(echo $PATH|sed 's/:/ /g')
" command.
Can you explain?
PS: And a anwser on Einstein47's question for you Ed.
If by "simple" you mean deleting just a few files, then I agree with you -exec rm {} \; should work OK.
In the early days of Unix (especially SCO Xenix) it was easy to overflow the command line buffer. The book Unix Power Tools, Articles 10.18 to 10.21, covers the overflow problem extensively.
Modern *NIXs do not over flow as easily, but, besides force of habit, these are the main reasons I still use xargs:
1) Especially if I'm doing something destructive like a move, I like to see the output of the find command. It's just as easy to pipe to xargs than fill in -exec.
2) Although I've really never run any personal tests, using xargs should be more efficient. If find discovers 10 objects, xargs executes rm only once, and not 10 times - once for each object.
3) Also, xargs can extend the functionality of the find:
The above command finds all txt files, and echos a deleting message as each file is removed. The xargs -I option replaces {} in the string with the results of find.
I don't think I've covered anything here that others is this forum haven't already said about xargs, but I hope this answer yours question.
>I don't quit get the "dirs=$(echo $PATH|sed 's/:/ /g')
The find command allows searching multiple directories:
find /usr/bin /bin /etc -type f ....
I want to search every directory in PATH; Since the PATH variable is colon delimited, I can get a list of all the directories by globally substituting a space for ":". Therefore:
Thanks for the explination Ed. I can see that you have earned your "old" title. The star
is for your patience with us "young whipper/snappers". (-: Einstein47 ("For every expert, there is an equal and opposite expert." - Arthur C. Clarke)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.