Removing the file extension in a text file bash
This question already has an answer here:
Just loop through the .log
files and move them:
for file in *.log
do
mv "$file" "${file%.log}"
done
This uses shell parameter expansion:
$ d="a.log.log"
$ echo "${d%.log}"
a.log
Using rename
to rename all .log
files by removing .log
from the end:
rename 's/.log$//' *.log
.log$
matches .log
at the end of the file name and it is being omitted by replacing with blank If you are using prename
, then you can do a dry-run first:
rename -n 's/.log$//' *.log
If satisfied with the changes to be made:
rename 's/.log$//' *.log
链接地址: http://www.djcxy.com/p/57086.html
下一篇: 删除文本文件bash中的文件扩展名