Mac linux rename command line to modify file names in batches

When my mac uses the command line to modify the name in batches, I found that there is no rename command:

zsh: command not found: rename

So use HomeBrew to install it first:

➜  ~ brew install rename

After the completion, you can directly use a simple one-line command to modify the naming of multiple files. The general format is as follows:

➜  ~ rename 's/old/new/' *.files 

Example:

Modify the prefix of the batch of png files from'ic_' to'ic_setting_':

(ic_launcher.png -> ic_setting_launcher.png)

➜  ~ rename 's/ic_/ic_setting_/' *.png 

Modify part of the naming of batch files:

(ic_setting_launcher.png -> ic_launcher.png)

➜  ~ rename 's/_setting//' *.png 

supplement:

You can also use:
modify the first 5 letters to xxxxx (note that ^... is 5.)

for i in `ls`; do mv -f $i `echo $i | sed 's/^...../xxxxx/'`; done

The usage is similar, the rest is up to us to use flexibly.

Guess you like

Origin blog.csdn.net/zxccxzzxz/article/details/53050091