How to remove many (200 000) files?
$ find /path/to/folder -type f -delete
You are doing everything right. It is the '*' that gives you a problem (the shell is expanding it into list of files instead of the find
). The right syntax could be:
cd <your_directory>; find . -type f | xargs rm -f
find <your_directory> -type f | xargs rm -f
(The latter is a bit less efficient since it will pass longer names to xargs
, but you will hardly notice :-) )
Alternatively, you could escape your '*' like this (however in that case it will also try also remove "." and ".."; it is not a biggie - you will just get a little warning :-) ):
find . -name '*' | xargs rm -f
find . -name "*" | xargs rm -f
find . -name \* | xargs rm -f
If your file names contain spaces then use this:
find . -type f -print0 | xargs -0 rm -f
The following command will delete all files from the current directory:
find . -type f -exec rm {} \;
you can try
find /path/to/folder -type f -print0 | xargs -0 rm -f
or
find /path/to/folder -type f -exec rm -f "{}" +
Kudos to quantas answer, here are some additions.
If you like to delete files with a particular name pattern you can write it like this. Also added -print so you can see what's happening as the files are being deleted.
sudo find /home/mydirectory -name "*.jpg" -type f -print -delete
This for instance deletes all jpegs in mydirectory.