Visit Our UNIX and Linux User Community


can you think of a better way?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can you think of a better way?
# 1  
Old 02-08-2002
can you think of a better way?

Hi folks,

I've been tasked with cleaning up some directories. A list will be provided to me that will contain the names of the files to be deleted. I'm probably looking at columnar format, so that makes life easier. The files will be contained in two or three subdirectories of a directory.

This is what I have been testing:

for A in `cat $LIST;
do
{
find . -name $A -exec rm {} \;
};
done

it works, but I wonder if there is a better way?
ideas?
-kristy
# 2  
Old 02-08-2002
Your script looks good.

You need to close the `cat ... statement with another ` .
Also, depending on your Flavor of UNIX, you probably don't need the brackets and semicolons.

In your cat statement you can put the full path of the file that contains the columnar list of the files to be deleted. I would hope that this list shows the full path of each file to be deleted as well.

You can also use the "-i" option if you want to double check the deletion of the file, but it looks like you already want to get rid of all of these files.


Here is my variation of your script. Yours was good, but I like to see a logfile output with errors as well.

The 2> delete.error.log will record any exceptions to your script. That you can look at later. This is good especially for more complicated scripts.


for A in `cat filename`
do
echo $A "is being deleted now" >> delete.log
find . -name $A -exec rm {} \;
echo $A "has been deleted" >> delete.log 2> delete.error.log
done



Smilie
# 3  
Old 02-08-2002
Computer

why thank you.
The missing ` was a typo (oops) and the full path of the list of files is named in my variables, which I didn't bother to copy here.
The log is a great idea, I will include that.
-kristy

Previous Thread | Next Thread
Test Your Knowledge in Computers #432
Difficulty: Medium
As of May 2017, 94.5% of the 10 million most popular web pages used JavaScript, according to w3techs.com.
True or False?

Featured Tech Videos