我正在重命名文件和目录.基本上,我想要做的就是去掉空格,并用下划线替换它们,最后改成小写.我一次可以执行一个命令:$重命名“ 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, linux, ubuntu

相关文章推荐

添加新评论,含*的栏目为必填