bash script to rename all files in a directory?

2019-04-10 09:13发布

i have bunch of files that needs to be renamed.

file1.txt needs to be renamed to file1_file1.txt
file2.avi needs to be renamed to file2_file2.avi

as you can see i need the _ folowed by the original file name.

there are lot of these files.

标签: linux bash shell
8条回答
老娘就宠你
2楼-- · 2019-04-10 10:08

One should mention the mmv tool, which is especially made for this.

It's described here: http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/mass-rename.html

...along with alternatives.

查看更多
成全新的幸福
3楼-- · 2019-04-10 10:11

I use prename (perl based), which is included in various linux distributions. It works with regular expressions, so to say change all img_x.jpg to IMAGE_x.jpg you'd do

prename 's/img_/IMAGE_/' img*jpg

You can use the -n flag to preview changes without making any actual changes.

prename man entry

查看更多
登录 后发表回答