首页 > 其他 > 详细

批量删除文件扩展名

时间:2015-07-25 20:08:44      阅读:291      评论:0      收藏:0      [点我收藏+]

目录中有如下两个文件

1.txt.file touch 2.txt.file

想要实现删除.file,即扩展名,可通过以下脚本快速实现

for file in $(ls *.file);do ext=${file%.*};mv $file $ext;done

其中${file%.*}为获取文件名,mv$file $ext为重命名操作


附加:echo ${file##*.}      可获取文件的扩展名

      echo ${file%.*}       可获取文件名

root@oldboy extension_name$file=1.txt.file

root@oldboy extension_name$echo ${file%.*}    最短匹配,获取文件名
1.txt
root@oldboy extension_name$echo ${file%%.*}  
1

root@oldboy extension_name$echo ${file##*.}   启用最长匹配,获取扩展名
file
root@oldboy extension_name$echo ${file#*.}
txt.file

批量删除文件扩展名

原文:http://xoyabc.blog.51cto.com/7401264/1678292

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!