LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-31-2007, 03:30 PM   #1
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 185

Rep: Reputation: 17
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?
 
Old 12-31-2007, 03:43 PM   #2
kiley_rodgers
Member
 
Registered: May 2003
Location: Chicago
Distribution: Slackware 9
Posts: 34

Rep: Reputation: 15
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.....
 
Old 12-31-2007, 03:44 PM   #3
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 185

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by kiley_rodgers View Post
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.....


Thats also some great info, but just for kicks, lets say I wanted to run it against the file I have already?
 
Old 12-31-2007, 04:18 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 12-31-2007, 05:43 PM   #5
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 185

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by David the H. View Post
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.

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?
 
Old 12-31-2007, 07:42 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
Aye ...
man bash
Search for loops ...

Or
http://tldp.org/LDP/abs/html/index.html



Cheers,
Tink
 
Old 12-31-2007, 07:58 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by David the H. View Post
Use a simple 'for' loop:

for f in $(cat thumbs.txt); do rm $f; done
safer with this if file names have spaces
Code:
for i in "$(cat file)".....
better still, use while loop. Eliminate the use of cat
Code:
while read line
do
 # blah 
done < file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command to print last line of a text file Micro420 Linux - General 3 01-25-2007 01:17 AM
command output to text file? meniscus Linux - Newbie 4 10-05-2006 05:29 AM
How to run a text file through a command prompt? Fillys6 Linux - Newbie 8 03-24-2005 02:21 PM
Command to find file with text chamanrana Linux - Software 10 12-02-2004 10:47 AM
VNCViewer will not run kwrite or dislay text file manza7 Linux - Software 3 07-21-2004 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration