Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the mmv command in linux

Shulou Source: shulou.com Published: 2022-06-01 14:56:18 09月15日 Update

This article mainly describes how to use mmv command in linux, has a certain reference value, interested friends can refer to, I hope you read this article after a great harvest, the following let Xiaobian take you to understand.

mmv command is mainly used to rename or move files and directories in Linux system, but it has certain limitations. mmv command does not support renaming multiple files at once.

environment

Centos7.7

Install mmv

By default, there is no mmv installation package in the Centos 7 network feed, we need to install the epel feed first, and then install the mmv tool.

#Download Aliyun's epel source file. [root@localhost ~]# wget http://mirrors.aliyun.com/repo/epel-7.repo--directory-prefix=/etc/yum.repos.d#clear yum cache and regenerate cache [root@localhost ~]# yum clean all && yum makecache#install mmv[root@localhost ~]# yum -y install mmv rename file using mmv Example 1

To remove duplicate extensions, such as.rar.rar.rar, and keep only one.rar, you can use the following command:

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

You can see that the extension has become a.rar. If it's convenient.

instance 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' Using mmv command to modify file names in bulk Using mmv command to modify file names in bulk Example 3

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

[root@localhost test]# mmv '*.jpeg' '#1.jpg' Using mmv to modify file names in bulk Using mmv to modify file names in bulk Example 4

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

[root@localhost test]# mmv '*.html.?? ' '#1.# 2#3.html'Use mmv command to modify file names in bulk Use mmv command to modify file names in bulk Explanation

The argument in the first single quote after Mmv is called From, and the argument in the second single quote is called To. Wildcards that can be used in From are *,?, []、;。The wildcards that can be used in To are #1,#2,#3…etc.# Sign plus number form, corresponding to each wildcard in From.

For example:

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

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

Thank you for reading this article carefully, I hope Xiaobian shared "How to use mmv command in linux" This article is helpful to everyone, but also hope that everyone will support more, pay attention to the industry information channel, more relevant knowledge waiting for you to learn!

Tags: File command name instance pattern extension article wildcard directory parameter quotation mark format cache support clear three value example interest at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno MariaDB macOS Docker