Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify file names in batches by Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to modify the file name in batches by Linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Environment 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 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 # clear yum cache and regenerate cache [root@localhost ~] # yum clean all & & yum makecache # install mmv [root@localhost ~] # yum-y install mmv use mmv to rename file instance 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.room2room3.html'. There are three wildcards in From mode, *,?,?. The To mode also corresponds to the From mode # 1, "2", "2", 3.

This is the end of the content of "how to modify the file name in batch by Linux". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report