Using MMV command to batch modify file name

Time:2021-2-13

stayLinuxUsing MV incommandYou can rename or move files and directories, but it does not support renaming multiple files at once. This paper introduces the use of MMV, using wildcard mode to move / copy / append / link multiple files

Environmental Science

Centos7.7

Install MMV

By default, there is no MMV installation package in the network source of centos7. We need to install the EPEL source first, and then install the MMV tool.

Download Alibaba cloud’s EPEL source file.

[[email protected] ~]# wget http://mirrors.aliyun.com/rep… –directory-prefix=/etc/yum.repos.d

Clear the cache and regenerate it

[[email protected] ~]# yum clean all && yum makecache

Install MMV

[[email protected] ~]# yum -y install mmv

Renaming file instances using MMV

Example 1

If you want to delete the duplicate extension, for example, the extension is.rar.rar.rar, only one. Rar is reserved. You can use the followingcommand
Using MMV command to batch modify file name

[[email protected] test]# mmv ‘...‘ ‘#1.#2’

Using MMV command to batch modify file name
You can see that the extension has become a.rarIt’s too late. Is it convenient.

Example 2

If you want to change the file name and extension, but do not change the serial number in the file, you can do this:
Using MMV command to batch modify file name

[[email protected] test]# mmv ‘file*.rar’ ‘text#1.zip’

Using MMV command to batch modify file name

Example 3

Convert all. JPEG files in the current directory to. JPG format:
Using MMV command to batch modify file name

[[email protected] test]# mmv ‘*.jpeg’ ‘#1.jpg’

Using MMV command to batch modify file name

Example 4

Add the.html.cn,.html.en,.html.deAmend to readcn.html,en.html,de.html
Using MMV command to batch modify file name

[[email protected] test]# mmv ‘*.html.??’ ‘#1.#2#3.html’

Using MMV command to batch modify file name

explain

The parameter in the first single quotation mark after MMV is calledFromThe second parameter in the single quotation mark is calledToFromThe wildcards that can be used in are*?[];ToThe wildcards that can be used in are#1,#2,#3…And so on. #Sign plus number, corresponding toFromEach wildcard in the.

For example:

[[email protected] test]# mmv ‘*.html.??’ ‘#1.#2#3.html’

In this example, the from pattern is'*.html.??'The to mode is'#1.#2#3.html'. There are three wildcards in the from pattern,*??. To mode also corresponds to from mode#1#2#3

summary

For more information, check out the manual# man mmv