//View Tip #251
» Remove DS_Store files from shared folders
» Count files by type
» Being selfish - Kick all users except you
» The poor man's REPL
ls | xargs rm
Sometime there are so many files in a directory than the rm command doesn't work
On this case the best option is to use ls in conjuntion with xargs
Similar Tips
» Remove empty directories» Remove DS_Store files from shared folders
» Count files by type
» Being selfish - Kick all users except you
» The poor man's REPL
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
ls | xargs rm
Sometime there are so many files in a directory than the rm command doesn't work
[root@server logs]# rm * bash: /bin/rm: Argument list too long
On this case the best option is to use ls in conjuntion with xargs
[root@server logs]# ls | xargs rm
Comments
Add your comment
crap! wrong again, this is it:
for filename in *; do
rm "$filename"
done
for filename in *; do
rm "$filename"
done
Posted 2009-02-12 23:07:48
If GNU Parallel http://www.gnu.org/software/parallel/ is installed:
ls | parallel -X rm
This will run fewer rm's and can be faster if you remove a lot of files. GNU Parallel is safe for filenames not containing newline (and with -0 it is even safe for those).
Watch the intro video: http://www.youtube.com/watch?v … paiGYxkSuQ
ls | parallel -X rm
This will run fewer rm's and can be faster if you remove a lot of files. GNU Parallel is safe for filenames not containing newline (and with -0 it is even safe for those).
Watch the intro video: http://www.youtube.com/watch?v … paiGYxkSuQ
Posted 2010-06-22 04:59:25


when there's too much files you do:
for filename in *; do
rm "$filename:
done
this is a shell construct and it will handle large lists correctly, and is also safe.