bash - rm all files except some -
when using sudo rm -r, how can delete files, exception of following:
textfile.txt backup.tar.gz script.php database.sql info.txt
find [path] -type f -not -name 'expr' -print0 | xargs -0 rm -- for example, delete non txt-files in current directory:
find . -type f -not -name '*txt' -print0 | xargs -0 rm -- the find | xargs combination useful.
if don't specify -type f find list directories, may not want.
the print0 , -0 combination needed if there spaces in of filenames should deleted.
Comments
Post a Comment