加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Bash脚本从文件名中删除前导空格

发布时间:2020-12-15 21:42:49 所属栏目:安全 来源:网络整理
导读:所以我有一堆文件,如: Aaron Lewis - Country Boy.cdg Aaron Lewis - Country Boy.mp3 Adele - Rolling In The Deep.cdg Adele - Rolling In The Deep.mp3 Adele - Set Fire To The Rain.cdg Adele - Set Fire To The Rain.mp3 Band Perry - Better Dig Two
所以我有一堆文件,如:

Aaron Lewis - Country Boy.cdg
 Aaron Lewis - Country Boy.mp3
 Adele - Rolling In The Deep.cdg
 Adele - Rolling In The Deep.mp3
 Adele - Set Fire To The Rain.cdg
 Adele - Set Fire To The Rain.mp3
 Band Perry - Better Dig Two.cdg
 Band Perry - Better Dig Two.mp3
 Band Perry - Pioneer.cdg
 Band Perry - Pioneer.mp3

我需要在bash或fish脚本中删除前导空格.

解决方法

要删除您提供的文件名中的前导空格字符,您可以使用:

IFS=$'n'
 for f in $(find . -type f -name ' *')
 do 
     mv $f ${f/./ /./}
 done

这个:

>将IFS更改为换行符;这样它就不会阻塞文件名中的空格.>查找当前目录中以空格开头的所有文件.>使用bash子字符串替换将每个文件移动到没有前导空格的文件名.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读