Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exclude files with RM

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I am deleting some old files in the fwg manner:

touch 200506271823 /home/temp/tempdate.txt
rm `find . ! -newer /home/temp/tempdate.txt -type f`

The above works perfectly but I have a small problem.. There are some files in the current dir which I dont want to delete.

How can I "exclude" them in my rm command ?

thnx

 
Something like this ?
rm `find . ! -newer /home/temp/tempdate.txt -type f | grep -v -f /path/to/ListOfExcludedFiles`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
unfortunately, its not getting the desired output.. I followed your suggestion and copied the files that I do not want to delete in to a temp dir, but executing the above cmd still deletes the files anyway..ie, the grep portion of the cmd is being ignored...

thnx
 
I strongly suggest you man grep if you want to properly try my previous post.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
In the Korn shell you can use a negative patter match. That is, you can match on everything except a list of patterns.

For example, if you were in a directory and wanted to delete every file EXCEPT [tt]*.sh[/tt], [tt]*.c[/tt], [tt]*.h[/tt], [tt]*.txt[/tt], and [tt]a*[/tt] (just for example), you would do the following...
Code:
rm !(*.sh|*.c|*.h|*.txt|a*)
You should test it with an [tt]ls[/tt] before doing the [tt]rm[/tt].

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top