Operating System - HP-UX
1834148 Members
1980 Online
110064 Solutions
New Discussion

Removing Input redirected files

 
SOLVED
Go to solution
Sanjay Verma
Super Advisor

Removing Input redirected files

Hi Friends,
I've approx. 10 files listed in a ascii file - 'JNK'. Using the rm command, I would like to delete only the files listed in my file 'JNK'. Can you let me know how this can be accomplished?
Co-operation - The biggest chain reaction
6 REPLIES 6
V.Tamilvanan
Honored Contributor
Solution

Re: Removing Input redirected files



Hi,

#for i in `cat JNK`
do
rm $i
done


HTH
Patrick Wallek
Honored Contributor

Re: Removing Input redirected files

Another, very similar, way would be

# for i in $(cat JNK)
do
echo "Removing file $i"
rm -i $i
done


The 'rm -i' will ask you if you are sure you want to remove the file. If you don't want to be prompted, make the rm statement read 'rm $i'.

Sanjay Verma
Super Advisor

Re: Removing Input redirected files

Hi Tamil,
When I execute your statement, it says - rm: cat non-existent.

Patricks statement works fine without any error mesg. Any suggestions?
Co-operation - The biggest chain reaction
John Dvorchak
Honored Contributor

Re: Removing Input redirected files

Ok how about on one line?

for i in `cat JNK`;do rm $i;done

And if you want to see the files:

for i in `cat JNK`;do echo $i;rm $i;done

If it has wheels or a skirt, you can't afford it.
John Dvorchak
Honored Contributor

Re: Removing Input redirected files

One more thing to clarify what I added the little ticks around the `cat JNK` are the back ticks below the tilde ~ character.
If it has wheels or a skirt, you can't afford it.
Sanjay Verma
Super Advisor

Re: Removing Input redirected files

Thanks for the clarification John. Cheers.
Co-operation - The biggest chain reaction