
我試圖在所有子資料夾中遞歸搜尋檔案名稱中帶有有點的檔案並刪除這些點(最後一個除外)
重新命名命令可以單獨工作,查找命令也可以,但它們不能一起工作:
find ./ -type f -execdir rename -n 's/\.(?=[^.]*\.)//g' *.txt \;
答案1
命令中的 glob-execdir
不起作用,最好find
搜尋您想要的檔案並rename
僅對它們運行:
find ./ -type f -name "*.txt" -exec rename -n 's/\.(?=[^.]*\.)//g' {} \;
事實證明您的rename
表達式不適用於路徑,請嘗試以下操作:
find ./ -type f -name "*.txt" -exec rename -n 's:\.(?=[^./]*\.)::g' {} \;