Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Global Deleting with Wildcards



Charles Muller wrote:
> When I do backups in DOS using batch files, I usually start off the
> script with a couple of lines like this, that clean out all of the various
> temp files so that they are not included in the backup set.
> 
> del d:\docs\*.tmp /s
> del d:\docs\temp.* /s
> del c:\temp\~*.* /s
> del c:\temp\*.*~ /s
> ...

"rm" will take wildcards, but it doesn't use the pattern to recurse 
subdirs -- instead, you'd need to use "find", like so:

find . \( -name "*.tmp" -o -name "temp.*" \) -exec rm -f {} \;

"find" recurses from a starting directory ("." in this instance) an runs 
a set of operations on each file.  Here, we test to see if the name is 
*.tmp or temp.*, and if so, rm -f the file.  Of course, you want to be 
careful with it. =)  Check the man on "find" for lots more tests and 
operations and description.

Word of warning:  be careful of what your shell does to things like "~", 
since that might have special meaning.  (No idea if it would actually 
mess with things, but it's safer to avoid it. =)

Lastly, you might try that above command this way:

find . \( name "*.tmp" -o -name "temp.*" \) -print

to see which files it plans to jump on.

Share and enjoy.

Larry


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links