Rename multiple files at once in Linux

If you've ever wondered how you can rename multiple files at once, instead of going one by one, then this is the mini tutorial you are looking for. In it we are going to teach you step by step how to proceed from the console of your favorite GNU / Linux distribution to be able to change the names simultaneously and in a simple and comfortable way, without having to do it independently and waste your time on it. If you have tried the cp or mv command, you will know that you cannot do it with several files simultaneously ...

But there are other ways, and one of these alternatives is using the mmv command. It is very likely that if you enter the mmv command in the terminal and execute it, you will find the typical message that the program is not installed, therefore, you can use the preferred package manager that you normally use and proceed to install the necessary package bearing his same name. With this package installed, you will have a more flexible tool than the original mv with which you can move, copy, append and rename files in batches and not individually.Actually with mmv as it is, you cannot do that alone, but with the help of the standard wildcards of which the Unix operating systems provide us, and these combined with mmv will allow us to change the name of several files at the same time. For example, imagine that we are in your home directory and you have three text files called c1.txt, c2.txt and c3.txt. You want to change those names to d1.txt, d2.txt and d3.txt:

mmv c \ * d \ # 1

And now if you list with a ls you will see that the names are what you were looking for. That is, the pattern c \ * (c1, c2, c3) has been changed to the pattern d \ # 1 (d1, d2 and d3) and referring to the first wildcard (1). And of course you can use other special characters to modify text strings, etc. For example, imagine that you have the files hello1.txt, hello2.txt and hello3.txt, and instead of the above after mmv you put the following:

mmv '* hol *' '# 1abc # 2'

The result would be abca1.txt, abca2.txt, and abca3.txt. And in the case of wanting to modify the extensions, then you could also without changing the names of all the files. Imagine that you want to replace the .txt with .htm:

mmv \ *. txt \ # 1.htm

And the result would be abca1.htm, etc.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

A comment, leave yours

Leave a Comment

Your email address will not be published.



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Bill said

    Interesting, for my part I usually use the graphical tool pyrename, very good.
    On the other hand, in the example to change .txt to .htm it is almost better to use .html, since .htm is a shortening made by Microsoft for its FAT file system that did not allow extensions of more than 3 letters back in the 90's when the web started (no names of more than 8 letters).

bool (true)