How to rename files in Linux Mint

How to rename files in Linux Mint

Renaming a file in linux – a very simple operation, but for newcomers to Linux this task can be difficult. Also there are some nuances and features that it is desirable to know experienced users, for example, a mass rename. In the GUI everything is very simple, but the flexibility gives you a terminal.

In this article we will look at how to rename a files in Linux Mint using the terminal and GUI, consider features such as massive batch rename files, and regular expressions.

1. How to rename a file in Linux Mint using mv:

In Linux there is a standard utility mv, which is intended to move files. But at its core, the movement is the same as and rename file linux, if you are in the same folder. Let’s first examine the syntax for this command:

mv option source-file destination-file

Now consider the main options of the tools you might need (man mv):

-f – overwrite the file if it already exists;
-i – ask whether to replace existing files;
-n – do not overwrite existing files;
-u – replace the file only if it has been changed;
-v – display the list of processed files;
To rename the file you simply invoke the utility without additional options. Just passing it the file name and the new name:

mv file newfile

How to rename files in Linux Mint

As you can see, the file was renamed. You can also use the full path to the file or move it to another folder:

mv /home/user/newfile.txt /home/user/test/newfile2.txt

How to rename files in Linux MintHow to rename files in Linux Mint

Please note that you must have write permissions to the folder in which you want to rename the files. If the folder belongs to another user, it may be necessary to run the program using sudo. But in this case it is better to run with -i option to randomly not delete anything.
In Your user directory /home/USER/ typically, you have all the rights.

Rename files using rename:

There is another command that enables you to rename the file. rename. It is specifically designed for this task, so it supports things like batch rename files and using regular expressions. The syntax of the utility is also more complicated:

rename option ‘s/old_name/new_name’ files


rename option old_name new_name files

Instead of the old name is a regular expression or partial name you want to change, the new name indicates what needs to be replaced. Files – the ones that need to be processed, to select files is to use a stand such as * or ?.

Consider options utility:

-v – display the list of processed files;
-n – test mode, in fact no action will not be performed;
-f – force overwrite existing files;
For example, rename all .htm files from the current folder to .html:

rename ‘s/\\.htm/\\.html/’ *.htm

How to rename files in Linux MintHow to rename files in Linux Mint

Or for images:

rename ‘s/\\.jpeg/\\.jpg/’ *

* indicates that the rename files linux will be executed for all files in the folder. Regular expressions can be used additional modifiers:

g (Global) is to apply to all found ;
i (Case Censitive) is not case sensitive.
Modifiers are placed at the end of a regular expression, before the closing quotation mark. Before you use such a design, it is advisable to check to make sure that you are not allowed anywhere errors, here comes the -n option. Replace all occurrences of DSC on photo names photos:

rename -n ‘s/DSCimage/photo/gi’ *.jpeg

How to rename files in Linux Mint

Will be processed DSC, DsC and dsc even, all the options. Since you used the -n option, the software only displays the image names that will be changed.

You can use not only the usual replacement, but a full-fledged regular expression to batch rename files, for example, will remake all the names to lower case:

rename ‘y/A-Z/a-z/’ *.jpeg

How to rename files in Linux MintHow to rename files in Linux Mint

From this example we see that even if the file already exists, it will not overwritten by default. Don’t forget to use the -n option so no accident damage.

Renaming files using pyRenamer:

Experienced users and beginners will enjoy the ability pyRenamer to rename multimedia files from their metadata. In addition, you can rename a single file if necessary. This tool completely implements the functionality of mv and rename with GUI.