linux文件替换空格分割,linux-用下划线替换空格并小写-文件名

我正在重命名文件和目录.基本上,我想要做的就是去掉空格,并用下划线替换它们,最后改成小写.我一次可以执行一个命令:$重命名“ s / / _ / g” *,然后是小写命令.但是,我正在努力实现所有这些目标.最重要的是,删除空格并用_代替,但不会小写.怎么会?

find /temp/ -depth -name "* *" -execdir rename 's/ /_/g; s,,?; ‘

原始文件名:

test FILE .txt

结果:(如果末尾有空格,请取出)

test_file.txt

解决方法:

rename 's/ +\././; y/A-Z /a-z_/'

或者,结合查找:

find /temp/ -depth -name "* *" -exec rename 's/ +\././; y/A-Z /a-z_/' {} +

要仅定位文件而不定位目录,请添加-type f:

find /temp/ -depth -name "* *" -type f -exec rename 's/ +\././; y/A-Z /a-z_/' {} +

简称

Would it be possible to rename the file with the last three characters

of the original file for example from big Dog.txt to dog.txt?

是.使用此重命名命令:

rename 's/ +\././; y/A-Z /a-z_/; s/[^.]*([^.]{3})/$1/'

标签:bash,ubuntu,linux

来源: https://codeday.me/bug/20191121/2049909.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值