Due to a script error (file_put_contents($text, $filename, FILE_APPEND)
instead of file_put_contents($filename, $text, FILE_APPEND)
I now have 4 million small text files in a folder.
I'd rather not nuke the whole folder, as a handful of useful files are in there.
All of the unwanted files have "jpg" in the middle of the filename, none of the wanted files do.
What's the quickest way to delete these? I can't even do a ls
without it hanging my console at the moment – which makes identifying the names of the files I want to keep hard, otherwise I'd just move them out of the folder and then delete the whole folder.
Is find . -name "*jpg*" -delete
the best option, or is there a better/quicker way?
Best Answer
With 4 million files,
rm /location/of/many/files/*jpg*
will probably fail withArgument list too long
error.Use
find
:or if
-delete
is not available: