Run command against text file
I recently copied my data over to my linux box from my windows box. I have all these Thumbs.db files all over the place now.
So I did this: find / -name Thumbs.db > thumbs.txt Now I have a text file with the location of every Thumbs.db file. Now I want to delete all those files, how can I run an rm command against the entries in this file? |
find / -name Thumbs.db -exec rm {} \;
you can also do find / -name Thumbs.db -exec rm -i {} \; if you would ilke it to ask for confirmation for each deletion.... change filename as needed..... |
Quote:
Thats also some great info, but just for kicks, lets say I wanted to run it against the file I have already? |
Use a simple 'for' loop:
for f in $(cat thumbs.txt); do rm $f; done This reads the contents of thumbs.txt (use '$()' to get the output of a command, 'cat' in this case) one line at a time into variable f, then runs the rm command on the contents of the variable ($f), and loops back to do the next line. I suggest you remember the 'for' loop syntax. It's probably the most useful bash command you can learn. |
Quote:
This is exactly what I was looking for thank you both! I will read up on the for syntax. Is there a man page or website I can read, something you can suggest? |
|
Quote:
Code:
for i in "$(cat file)"..... Code:
while read line |
All times are GMT -5. The time now is 06:52 PM. |