我有许多带有 .txt 扩展名的文件。 如何在linux中删除多个文件的.txt扩展名?
我发现了
rename .old .new *.old
将 .old
扩展替换为 .new
我也想对子文件夹中的文件执行此操作。
最佳答案
rename
有点危险,因为根据它的manual page :
rename will rename the specified files by replacing the first occurrence of...
它会很乐意对像 c.txt.parser.y
这样的文件名做错事。
这是一个使用 find
和 bash
的解决方案:
find -type f -name '*.txt' | while read f; do mv "$f" "${f%.txt}"; done
请记住,如果文件名包含换行符,这将中断(很少见,但并非不可能)。
如果你有 GNU find,这是一个更可靠的解决方案:
find -type f -name '*.txt' -print0 | while read -d $'\0' f; do mv "$f" "${f%.txt}"; done
关于Linux:删除多个文件的文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4509485/