Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the mmv command to modify file names in batches

Shulou Source: shulou.com Published: 2022-06-01 02:57:04 10月12日 Update

This article mainly introduces how to use the mmv command to modify the file name in batches, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!

Environment

Centos7.7

Install mmv

By default, there is no mmv installation package in Centos7's network source, so we need to install the Epel source before installing the mmv tool.

# download the epel source file of Aliyun. [root@localhost ~] # wget http://mirrors.aliyun.com/repo/epel-7.repo-- directory-prefix=/etc/yum.repos.d# clears the yum cache and regenerates the cache [root@localhost ~] # yum clean all & & yum makecache# installation MMV [root @ localhost ~] # yum-y install mmv

Rename a file instance using mmv

Example one

To delete duplicate extensions, such as .rar.rar.rar, leaving only one .rar, you can use the following command:

[root@localhost test] # mmv'*. *'# 1.room2'

You can see that the extension has become a .rar. Isn't it convenient.

Example two

If you want to change the file name and extension, but not the sequence number in the file, you can do this:

[root@localhost test] # mmv 'file*.rar'' text#1.zip'

Example three

Convert all files in .jpeg format in the current directory to .jpg format:

[root@localhost test] # mmv'* .jpeg''# 1.jpg'

Example 4

Modify .html.cn, .hml.en, .html.de in the current directory to cn.html,en.html,de.html

[root@localhost test] # mmv'* .html.?

explain

The argument in the first single quotation mark after the Mmv is called From, and the parameter in the second single quote is called To. The wildcards that can be used in From are *,?, [], and;. The wildcard characters that can be used in To are # 1, "2," and 3. Wait. The # sign plus numeric form corresponds to every wildcard in From.

For example:

[root@localhost test] # mmv'* .html.?

In this example, the From mode is'* .html.? 'and the To mode is' # 1. Html. 3. HTML'. There are three wildcards in From mode, *,?,?. The To mode also corresponds to the From mode # 1, "2", "2", 3.

The above is all the contents of the article "how to use the mmv command to modify file names in batches". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: File instance pattern extension wildcard command name content parameter quotation mark format directory article cache clear three value example interest buddy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Huawei OPPO Reno NVidia