如何在當前工作目錄下遞歸地刪除所有沒有.txt
和.exe
擴展名的文件?我需要一個班輪。如何刪除沒有特定擴展名的文件?
我想:
find . ! -name "*.txt" "*.exe" -exec rm -r {} \
find -type f -regextype posix-extended -iregex '.*\.(txt|exe)$'
如何在當前工作目錄下遞歸地刪除所有沒有.txt
和.exe
擴展名的文件?我需要一個班輪。如何刪除沒有特定擴展名的文件?
我想:
find . ! -name "*.txt" "*.exe" -exec rm -r {} \
find -type f -regextype posix-extended -iregex '.*\.(txt|exe)$'
試試這個。
find . -type f ! -name "*.exe" ! -name "*.txt" -exec rm {} \;
上面的命令將刪除所有比當前目錄和遞歸子目錄中的.exe和.txt擴展名的文件的其他文件。
謝謝,它的工作。 –
如果你有GNU找到與-delete
行動:
find . -type f ! \(-name '*.txt' -o -name '*.exe' \) -delete
如果沒有:使用-exec ... {} +
與鏈接的參數執行rm
只是一次
find . -type f ! \(-name '*.txt' -o -name '*.exe' \) -exec rm -f {} +
。
我認爲這可以幫助你: http://unix.stackexchange.com/questions/153862/remove-all-files-directories-except-for-one-file –
你的一個班輪命令工作? – sureshkumar
他們沒有工作。該鏈接也沒有幫助。 –