2017-01-30 134 views
0

如何在當前工作目錄下遞歸地刪除所有沒有.txt.exe擴展名的文件?我需要一個班輪。如何刪除沒有特定擴展名的文件?

我想:

find . ! -name "*.txt" "*.exe" -exec rm -r {} \ 
find -type f -regextype posix-extended -iregex '.*\.(txt|exe)$' 
+1

我認爲這可以幫助你: http://unix.stackexchange.com/questions/153862/remove-all-files-directories-except-for-one-file –

+0

你的一個班輪命令工作? – sureshkumar

+0

他們沒有工作。該鏈接也沒有幫助。 –

回答

1

試試這個。

find . -type f ! -name "*.exe" ! -name "*.txt" -exec rm {} \; 

上面的命令將刪除所有比當前目錄和遞歸子目錄中的.exe和.txt擴展名的文件的其他文件。

+0

謝謝,它的工作。 –

1

如果你有GNU找到與-delete行動:

find . -type f ! \(-name '*.txt' -o -name '*.exe' \) -delete 

如果沒有:使用-exec ... {} +與鏈接的參數執行rm只是一次

find . -type f ! \(-name '*.txt' -o -name '*.exe' \) -exec rm -f {} + 

相關問題