Results 1 to 10 of 14
I need help with something. I use the find command to create lists of files of a certain name (or such) that get stored as text files. Sometimes, later on, ...
- 05-14-2008 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 90
Deleting files stored in a text file
I need help with something. I use the find command to create lists of files of a certain name (or such) that get stored as text files. Sometimes, later on, i want to delete this whole list. I need a command that will look in the text file, read the paths and names, and delete the named files. I suspect it involves cat and grep, but im not quite sure how.
the files are created with this or similar:
find / -iname "name" >> /lists/blah.txt
i need to be able to delete all the listed files in that text file. any help is appreciated.
- 05-14-2008 #2
- 05-14-2008 #3Just Joined!
- Join Date
- Nov 2006
- Posts
- 90
cool thanks!!!!!!!!
- 05-17-2008 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Quicker would be
- no loops necessary.Code:xargs rm -rf </lists/blah.txt
- 05-17-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Though both ways will fail if the list is long enough. So I prefer this:
Code:cat filename.txt | while read file; do rm "$file"; done
- 05-17-2008 #6Just Joined!
- Join Date
- Nov 2006
- Posts
- 90
ok thats cool, thanks guys, i really appreciate it. also, what if Im looking for a certain thing like
filepath/filename detected
filepath/filename deleted
filepath/filename update failed.
and i want to find all of the lines with update failed and then remove the file that failed. reason i ask is the output of bdc antivirus cant remove zip files so it does something like this (cant get real output right now, but if you would like it, let me know):
/mnt/hda1/Documents And Settings/Owner/Temorary Files/ax00340340.zip:virus.messupstuff update failed.
I have to use a scanner like bdc, clam is too paranoid and deletes files that i would rather it not like zips that have too much compression or gag viruses that dont do any harm
- 05-18-2008 #7Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
- 05-18-2008 #8Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
It's not xargs, it's the shell.
As far as I know, there's a limit on how long a command can be, and that has nothing to do with the command, it's a limitation of the shells themselves.
The while loop will always work, because the command is not long, only a single argument is passed on each iteration.
I would be more than glad to hear proof of the opposite, but I think that I am right.
EDITED: I am not sure anymore about the xargs stuff, I will have to research about it. There's no need to be that harsh though. I am sure you are perfect and never commit mistakes, but I am just a mere mortal and I am happy to stand corrected, though if possible in a more friendly way. I don't intentionally spread misleading statements.
Cheers and take it easy
- 05-18-2008 #9Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Yes, I know the shell has a limit as to how long the command can be (4096 bytes?) - xargs was invented to overcome that problem by fitting as many of its stdin fields to the command to be run, exec-ing the command as many times as it takes to exhaust that list. Thus it should never blow the shell's limit, unless it's been poorly implemented, which is unlikely. Also, the use of xargs is quicker than a for loop because it doesn't have to exec the command for every file, and is every bit as reliable. And it's less to type.

Sorry if you thought my previous post was a bit harsh - that wasn't my intention - but you did state categorically that "both ways will fail", which isn't true.
- 05-18-2008 #10Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
No harm done. I apologise as well. I wan't in the best mood today and I should have refrained from posting.
No problem. I stand corrected and that's a good thing, because I learned something and my innacurate statement will not confuse anyone now that it's been corrected.
All in all it's just another brick in the wall
Thanks.


Reply With Quote
