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?
jpg
in the name in the middle, or anywhere at all? – schaiba Nov 13 '19 at 13:00rm -f /location/of/many/files/*jpg*
– schaiba Nov 13 '19 at 13:03find . ! -name '*jpg* -exec mv -t path {} +
and once you are sure you have your files, nuke the dir. – schrodingerscatcuriosity Nov 13 '19 at 13:04bash: /usr/bin/rm: Argument list too long
– Codemonkey Nov 13 '19 at 13:04find /location/of/many/files/ -maxdepth 1 -type f -name '*jpg*' -delete
– pLumo Nov 13 '19 at 13:05find
is the way in this case. – schaiba Nov 13 '19 at 13:07.bash_whatever
, ssh files etc. Could I accidentally kill my session and prevent myself by logging back in using your method? – Codemonkey Nov 13 '19 at 13:08