Koozali.org: home of the SME Server
Legacy Forums => General Discussion (Legacy) => Topic started by: baw on January 28, 2005, 03:16:47 AM
-
I have a file server that has a shared network drive. This drive has suddirectories with files within them. What I need to do is purge *.bak. Since the drive has over one thousand suddirectories, I need to figure out how to remove the *.bak files within the subs with one command.
Is there a way for me to accomplish this?
Thanks for the help.
BAW
-
Read man rm. The -r option should interest you.
-
I must be missing something here. I have tried the rm command with the -r, -R, and --recursive options many different ways.
To test the situation, I have set up a temp directory with three subdirectories. Each subdirectory has two files in it, a .dwg and .bak file. I am trying to use the rm command as shown:
rm -rf ../temp/*.bak
The only time this works is if I point directly to one of the subdirectories. I need to remove all of the .bak files in one command. I use to use a batch file from a windows wkstn. The server that I am trying to do this on has over a thousand subdirectories under the main dwg directory.
Regards,
BAW
-
You should try the command find. (pointing to man find)
Something like
cd directory
find . *.bak -exec /bin/rm {} \;
Test this first of course, rm is very powerfull. You could test by replacing the "/bin/rm" by "ls" which should give you the filenames,
find . *.bak -exec ls {} \;
or add an -print to get some verbose output:
find . *.bak -print -exec /bin/rm {} \;