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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a script that will delete files out of directories.

Status
Not open for further replies.

dalascby

Programmer
Oct 30, 2000
13
US
I need a script that will go into all of the subdirectories of a directory and delete files "xxx", "yyy" and "zzz" (for example) out of each subdirectory. In other words, it has to go into a directory, figure out which files in that directory are "directories", go inside "those" directories...and delete files that I designate. I am brand new to Unix...help!!
 
Recursively delete all "plain" files starting at /path/to/start that are named "xxx":

find /path/to/start -type f -name 'xxx' -exec rm {} \;

Recursively delete all "plain" files starting at /path/to/start start that start with "xxx":

find /path/to/start -type f -name 'xxx*' -exec rm {} \;

Recursively delete all "plain" files starting at /path/to/start that start with "xxx*" OR "yyy*":

find /path/to/start -type f \( -name 'xxx*' -o -name 'yyy*' \) -exec rm {} \;

For best results, do a $ man find first. There are also lots of other neat options for find that may more closely suit your needs and the syntax may vary for different flavors of UNIX.

HTH,

Russ
bobbitts@hotmail.com
 
Russ,

Your "OR" code doesnt' seem to be working properly.
 
That was why I mentioned doing a "man find" on your system. Works fine on Solaris 2.5.1, but I can't vouch for any others. What is the problem you're having and what OS?

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top