How exclude files / folders for remove [duplicate]

2020-06-16 02:43发布

How can I remove all in folder and exclude specific folders and files?

(As example with tar: tar --exclude="folder").

Edit: I can delete files and folders.

2条回答
Melony?
2楼-- · 2020-06-16 03:06

NOTE: Be careful running the following commands.

find . -type 'f' | grep -v "NameToExclude" | xargs rm 
find . -type 'd' | grep -v "NameToExclude" | xargs rmdir
查看更多
别忘想泡老子
3楼-- · 2020-06-16 03:15

The rm function does not have an exclude function. Instead you can use rm *.txt to delete only text files, rm *.pdf to delete only PDF files, rm a* to delete only files starting with the letter a, rm *d to delete only files ending with the letter d, etc.

Using this method, you can relatively quickly delete all the files except the ones you don't want to.

查看更多
登录 后发表回答