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

Delete files from list 1

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have a file which contains a list of files to be deleted.

What simple command should I use with that file as input to delete all the files listed in one go?

I tried rm -f `cat /tmp/filename` but that does not work

Many thanks,
 
Echoing usually replaces CR with space so try
Code:
rm -f $(echo $(cat /tmp/filename))

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
this does not work I get a variable syntax error
 
but that does not work
Can you please be more descriptive ?
Some guesses:
rm -f $(</tmp/filename)

while read f
do rm -f "$f"
done</tmp/filename

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
fabien,
I remember having successfully done it the way you describe.
Do you get any error messages?
Do you use absolute or relative path names?

An alternative would be:
for i in `cat /tmp/filename`
do
rm $i
done

hth
 
I've tested my version
Code:
rm -f $(echo $(cat /tmp/filename))
and it works a treat using ksh on AIX 5.1

What OS and shell are you using?

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
another idea:
Could the problem be inside your file /tmp/filename ?
filenames containing wildcards, special characters, blanks and the like?
hth
 
Columb,

I tried ksh on Sun Solaris and it worked like you said. I was using csh. What would be the csh version then?

Cheers!
 
$() construct doesn't exit in csh;
the backtick equivalent of columb's idea:
rm -f `echo \`cat /tmp/filename\``
hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top