I have a file that exported a bunch of file names that need to be removed. I need to know how to go about removing each file without having to issue it one at a time at the command line.
I've thought about just cating it inside a for
loop, which would probably work, but wanted to know if there was an easier, or even a better solution to doing this.
Thanks.
No need for
cat
or a loop:`` characters can be replace with $()
from bash man page:
If you need to remove lots of files this is several times faster than xargs + rm, and many many times faster than a shell loop.
Just for the hell of it, just make the file into a script and execute it handles whitespace and most other awkward characters and is simple. Does not spawn more processes than most of the above methods.
Current answers are sufficient - xargs may fail if you have too many files though - in that case you'll need some kind of loop.
Also - when performing this kind of thing it's not a bad idea to , rather than delete, move the files to another folder, so you can manually verify that some weird filenames haven't made some kind of mistake. Then, when you are confident you are okay, just delete the folder.
Not the best one, but it works -:)
One more:
xargs rm < /path/to/file
(works if you have one filename per line)