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

What is the method for Linux system to rename multiple files at a time?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you what is the method of renaming multiple files in Linux system at a time, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The mmv program can be used in the default repository of Debian-based systems. To install it on Debian, Ubuntu, Linux Mint, run the following command:

$``sudo``apt-get ``install`` mmv we assume that you have the following files in the current directory.

$``ls`a1.txt a2.txt a3.txt now, you want to rename all files that start with the letter "a" to start with "b". Of course, you can do this manually in a few seconds. But think about whether you have hundreds of files you want to rename? This is a very time-consuming process. The mmv command is very helpful at this point.

To rename all files that begin with the letter "a" to those that begin with the letter "b", simply run:

$mmv a\ * b\ ``# 1 Let's check to see if the files have been renamed.

As you can see, all files starting with the letter "a" (that is, a1.txt, a2.txt, a3.txt) are renamed to b1.txt, b2.txt, b3.txt.

explain

In the above example, the first parameter (a *) is the "from" mode, and the second parameter is the "to" mode (bread1). Based on the above example, mmv will look for any file name that starts with the letter "a" and rename the matching file, the "to" pattern, based on the second parameter. We can use wildcards, such as *,? And [] to match one or more arbitrary characters. Please note that you must escape using wildcards, or they will be extended by shell and will not be understood by mmv.

# 1 in "to" mode is a wildcard index. It matches the first wildcard in the "from" pattern. # 2 in "to" mode will match the second wildcard, if any, and so on. In our example, we only have one wildcard character (asterisk), so we write a # 1. And the # symbol should also be escaped. In addition, you can enclose the pattern in quotation marks.

You can even rename all files with a specific extension to another extension. For example, to rename all .txt files in the current directory to .doc file format, simply run:

$mmv\ * .txt\ ``# 1.doc this is another example. Let's assume that you have the following documents.

$``ls`abcd1.txt abcd2.txt abcd3.txt you want to replace the first occurrence of "abc" with "xyz" in all files in the current directory. What would you do?

It's simple.

Note that in the above example, the pattern is enclosed in single quotation marks. $mmv ``* abc*'``'# 1xyzroom2'.

Let's check to see if "abc" is actually replaced with "xyz".

$``ls`xyzd1.txt xyzd2.txt xyzd3.txt see? The files abcd1.txt, abcd2.txt, and abcd3.txt have been renamed xyzd1.txt, xyzd2.txt, and xyzd3.txt.

Another noteworthy feature of the mmv command is that you can print the output using the-n option instead of renaming the file, as shown below.

$mmv-n a\ * b\ ``1`a1.txt-> b1.txt``a2.txt-> b2.txt``a3.txt-> b3.txt allows you to simply verify what the mmv command actually does before renaming the file.

See the man page for more details.

$``man`` mmv Update: Thunar File Manager

The Thunar File Manager has a built-in bulk rename option by default. If you are using Thunar, renaming files is much easier than using the mmv command.

Thunar is available in the default repository for most Linux distributions.

To install it on an Arch-based system, run:

$``sudo`` pacman-S thunar on RHEL and CentOS:

$``sudo``yum ``install`` thunar on Fedora:

$``sudo``dnf ``install`` thunar on openSUSE:

$``sudo``zypper ``install`` thunar on Debian, Ubuntu and Linux Mint:

After $``sudo``apt-get ``install`` thunar is installed, you can start the batch renaming program from the menu or from the application launcher. To start it from the terminal, use the following command:

The batch renaming of $thunar-B is as follows.

Click +, and then select the list of files to rename. Batch renaming can rename the file name, the file suffix, or rename the file name and suffix at the same time. Thunar currently supports the following batch renaming:

Insert date or time

To insert or cover.

Serial number

Delete character

Search and replace

Upper or lowercase

When you select one of the conditions from the list of options, you will see a preview of the changes in the New name column, as shown in the screenshot below.

After selecting the condition, click the rename File option to rename the file.

You can also open the batch rename from Thunar by selecting two or more files. After selecting the file, press F2 or right-click and choose rename.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The above is how Linux renames more than one file at a time. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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: 286

*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