Rename Linux Files

There are actually many ways to rename files on Linux, but in this article we review the most commonly used Linux file renaming methods and we found three ways, what are they? Let's see the explanation below:

Rename Files With the mv Command

This mv command has a function to rename files or folders in Linux. Through this command you can also move files to another directory. So, how do you do it?

Step1:  Open the terminal software or via the command line. Next, for vps users try to log into the server by running the following commands, namely:

ssh root@192.168.1.1 -p 22

Step 2: Please login ubuntu vps server. If you have successfully logged in, here is the basic structure of the mv command, namely:

mv [OPTIONS 1] [OPTIONS 2] source destination

Now, here is an explanation of each parameter:

  • mv: a command to rename or move files in Linux.
  • [OPTIONS 1]: the old filename you want to replace.
  • [OPTIONS 2]: a new file name that you can use.
  • Source: the location of the old folder to be moved.
  • Destination: the location of the new folder to move the files to.

Please note that this mv command can also be combined with several other options, namely:

-f: provides no warning message before the file is overwritten.

-i: provides a warning message before the file is overwritten.

-u: to move recent files or files that don't have a source yet.

-v: to show all functions of the existing mv command.

Rename Files With the Rename Command

This command is slightly different from the mv command because rename on Linux only serves to rename files. In addition, this command can be used to change extensions, give or edit additional names to files.

For some Linux distros, the rename command is usually installed by default. However, if it is not installed on your device then run the following command line command according to your device.

Ubuntu distro, Debian, and its derivatives, namely:

sudo apt install rename

CentOS, RHEL, and their derivatives, namely:

sudo yum install rename

If the above commands have been installed on your computer/laptop, please practice some of the following Linux file rename command options!

How to Rename Linux Files at Once

As you know, files in Linux can be renamed all at once. If you want to rename many files at once, then you need to know what files are in the directory.

Now, run the following command on the Linux terminal, namely:

ls   

The ls command can view all the files in the Linux folder. Next, here's the structure of the rename command:

rename ‘s/old-name/new-name/’ *.extension

Keterangan sintaks di atas, yakni:

rename: command renames a file.

s: command to rename multiple files in Linux at once.

old-name: name old file.

new-name: the name of the new file.

*.extension: command changes all files in Linux with the extension.

How to Rename Linux File Extensions

Now, you need to know that the rename command in Linux can also be used to change file extensions in Linux. In order to run the command, you need to know a list of files with specific extensions, such as .txt.

First, execute the command:

ls *.txt

When the Is *.txt command above is executed, it will produce the output of displaying all the .txt extension files in the Linux folder. Then, first understand the basic syntax used to change the following file extensions, namely:

rename ‘s/old-extension/new-extension/’ *.extension

Explanation of each syntax:

rename: command changes the file extension.

s: a description to change the extension of some files in Linux.

old-extension: the old file extension of Linux.

new-extension: a new file extension from Linux.

*.extension: command changes all files in Linux with the latest extension.

How to Add Linux File Names

The next way to rename a Linux file is to give the file an additional name. You can try this step to update the name of one specific Linux file. Alternatively, you can also change several files at once but keep the extension the same.

Now, the command structure that must be executed is more or less as follows:

rename ‘s//additional_/’ *.extension

Syntax description of the command structure above:

rename: command adds the names of files in Linux.

s: a caption that indicates you can add the names of multiple files at once in Linux.

additional_: additional name to be used in the file.

*.extension: caption appends the name of all files in Linux with an extension.

How to Change an Additional Name

The last Linux file rename command option changes the additional name. As in the previous point, you can use this command, both on one file and several files in Linux.

Well, the basic syntax of this rename command is:

rename ‘s/old-additional_/new-additional_/’ *.extension

The description of the syntax above is:

rename: command changes the additional name of the file.

s: a caption indicating that you can change the additional names of some Linux files.

old-additional_ : an extension of the old name of the Linux file.

new-additional_ : add a new name for the Linux file.

*.extension: caption renames all Linux files with the extension.

Now, do you know how to rename Linux files easily like the method above? It's very easy to practice, isn't it?! After reading all the explanations above, you have learned two ways to rename files in Linux, namely with the mv and rename commands.

This mv command/command can be used to rename files in Linux. You can also use this command to move the file to another directory.

Meanwhile, this rename command/command has more complete options than the mv command. This command can do many things including renaming multiple files at once, changing the file extension, to giving additional names to the file.

Of course, both commands are very useful in the activity of managing files in Linux. In addition, you can also use both options according to your needs and situation.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.