How to Rename a File in Linux in 2023 (4 Methods) #GeekLeap

Once you begin studying one thing new, even the best duties really feel complicated, and that may be irritating for anybody. Say renaming a file is among the most elementary duties for file administration, however newbies would possibly face problem in renaming a file or batch renaming information in Linux. That will help you with it, we’ve defined 4 simple methods to rename a file and even a number of information in Linux utilizing the command line interface (CLI) in addition to the GUI.

Renaming Information in Linux (2023)

First, we are going to clarify the best way to use the mv and rename instructions to rename information utilizing the Command Line (or Terminal) in Linux. After which, we are going to discover ways to rename or batch rename information utilizing GUI instruments, together with GPRename and the native file supervisor in your Linux distro.

Rename Information Utilizing the Command Line

Despite the fact that utilizing the command line for the best of duties would possibly sound intimidating at first, it boasts a variety of options and is the quickest solution to rename information in Linux. Right here, we’re utilizing the mv and rename instructions, and each of them will work in any Linux distribution.

Rename Information Utilizing mv Command

The mv command stands for “transfer” with its main objective being to maneuver each information and directories within the Linux file system. However we are able to additionally use the mv command to rename information. The syntax for the mv command is:

mv <choices> <source_file> <destination_file>

Choices Description
--backup to make a backup of every current vacation spot file
-f to stop the command from making a immediate earlier than overwriting
-i to immediate earlier than transferring
-u to maneuver the file provided that the <source_file> is newer than the <destination_file>
-v to point out details about the present operation being performed
-n to stop an current file from being overwritten

Observe: For those who use any of the -i, -f, -n flags greater than as soon as, solely the ultimate one takes impact.

Rename Single File Utilizing the mv Command

To rename a single file utilizing the mv command, use the below-given syntax:

mv -v <old_file_name> <new_file_name>

The command ends in the output under as affirmation, and you may confirm the modifications made utilizing the ls command.

renamed '<old_file_name>' -> '<new_file_name>'

rename a single file using the mv command

Within the above instance, we’re renaming the file “mini-course-10.pdf” to “test-1.pdf” utilizing the mv command. Right here, the syntax appears to be like like this:

mv -v mini-course-10.pdf test-1.pdf

After that, you possibly can confirm the change from the output of the mv command (highlighted within the picture above), or you possibly can additional confirm the output utilizing the ls command. You will notice the renamed file within the listing of information in that listing.

Rename A number of Information utilizing the mv Command

The mv command may also be used to rename a number of information in a listing with some modifications. Right here we are going to use some new instructions together with the mv command. The command can show to be obscure with simply uncooked syntax, so we’ve used it for instance under.

for i in *.pdf;do 
        mv -v "$i" "$i/$i:0:4/instance"

The above code snippet would possibly look advanced to newcomers, however it’s simple to grasp. As soon as executed, the code snippet will look by means of the listing of information with the extension “.pdf” repeatedly. It is going to then substitute the primary 4 characters of every file title with the alternative textual content “instance“. Lastly, it is going to cease executing when all of the information have been renamed.

rename multiple files with the mv command

Rename Information Utilizing rename Command

The rename command solves the complexity of the mv command with easy-to-use syntax for each single and a number of file renaming. The rename command usually comes pre-installed on most distros. If not, you possibly can simply set up it utilizing a easy command:

  • For Debian-based methods

sudo apt set up rename

  • For Fedora-based methods

sudo yum set up prename

  • For Arch-based methods

sudo pacman -S set up rename

The syntax to make use of the rename command in Debian-based methods is as follows:

rename <choices> 's/<old_name>/<new_name>/' <file_names>

For the reason that rename command makes use of Perl within the backend, there are three kinds of common expressions – match, substitute, and translate in Perl. The rename command makes use of the “substitute” and “translate” common expressions. Within the syntax above, the “s” is used to specify that you’ll use the substitute expression.

For RedHat, Fedora-based methods, it is advisable to use the next command syntax:

rename <choices> <old_name> <new_name> <file_name>

A number of the frequent choices to work with the rename command are:

Choices Description
-v Exhibits details about the present operation
-n stands for “no motion” and is used for testing to see how the information are going to get affected after the operation
-f used to pressure overwrite the file title
Rename a Single File

The rename command works very similar to the mv command when renaming a single file. To rename a single file, use the next syntax:

rename -v 's/<original_name>/<new_name>/' <file_name>

renaming a single file using the rename command
Rename A number of Information

The primary benefit of the rename command over the mv command comes into play when renaming a number of information. The syntax is less complicated and quicker to make use of. Right here’s what it reads like:

rename <choices> 's/<old_name>/<new_name>/' <files_to_rename>

The above syntax is just like the one we used for renaming a single file apart from the <files_to_rename> half, the place you should use a standard sample utilizing wildcards with a purpose to acknowledge all information in a listing.

renaming all .txt files using the rename command
Rename Information Partially

Suppose you’ve got used areas in all of your file names, and now, you need to substitute the areas with underscores. You need to use the rename command and convert areas to underscores utilizing the syntax proven under:

rename -v 'y/<original_part>/<part_to_replace>/' <files_to_rename>

Right here, place the half that it is advisable to substitute within the <original_part>, and write the sample you need to substitute the <original_part> throughout the <part_to_replace>. The y is used to suggest that you’re utilizing the “translate common expression.

For the above state of affairs to interchange areas with underscores, use the given command:

rename -v 'y/ /_/' <files_to_rename>

Right here, the is used to deal with the underscore as a personality and never part of the command syntax.

replacing spaces with underscores using the rename command
Change The Case of The Filenames

With the rename command, you possibly can even substitute the lowercase characters with their respective uppercase characters and vice versa. To switch the lowercase characters with uppercase ones, use the next syntax:

rename 'y/a-z/A-Z/' <files_to_replace>

And to interchange uppercase characters with lowercase ones, use this syntax:

rename 'y/A-Z/a-z/' <files_to_replace>

change the name from lower case to upper case using rename command

Rename Information utilizing the GUI in Linux

The GUI methodology might be a boon for these customers who discover the command line daunting. For the GUI methodology, we’re utilizing the Nautilus File supervisor and Pyrenamer in Ubuntu 20.04 LTS, however relaxation assured that these strategies will work on any distribution – albeit with slight modifications in some.

Rename Information Utilizing File Supervisor

This is among the best strategies to rename information in Linux. Each Linux desktop distribution comes pre-installed with a file supervisor equivalent to Nautilus, Dolphin, Thunar, and so forth. We have now defined how you should use these file managers to rename information, so maintain studying.

Rename A Single File

1. Open the File supervisor of your alternative and navigate to the file which you need to rename. Choose the file and right-click on it.

2. From the right-click menu, choose the “Rename” choice. Alternatively, press the F2 button in your keyboard to rename information with out utilizing the mouse.

Rename option in right click menu in GUI

3. Then, sort within the new title for the file and click on on “Rename” or hit Enter on the keyboard. And that’s it.

Rename a single file using file manager
Rename A number of Information Utilizing File Supervisor

1. Choose a number of information you need to rename by urgent the Shift button after which right-click on the chosen information to open the context menu.

2. On this context menu, choose the “Rename” choice. Or, you possibly can press the F2 button on the keyboard to entry the rename choice.

Rename opton in the right click menu

3. This may open a brand new rename window, as proven under. Right here, you get two choices to rename the information, so let’s discover ways to use each of them one after the other.

Rename Utilizing a Template:

1. On this choice, you will note a textual content field with the default worth as [Original file name]. Within the textual content field, enter the frequent title that will probably be used for all of the information.

rename using a template

2. We’re utilizing “test_” because the frequent file title right here. Subsequent, click on on “+Add” subsequent to the frequent title and select the automated numbering scheme for use as a novel differentiator for every file.

adding the common name and unique identifier to the file names

3. Then, select the order of naming the information from the “Automated Quantity Order” drop-down menu. You possibly can select between Ascending, Descending, and extra.

choose the naming order of files drop down

4. Confirm the modifications within the backside pane and at last click on on “Rename” within the high proper nook.

verifying the changes before finally renaming the files

Discover and substitute textual content:

You need to use this feature when your file title already comprises a standard title, however it is advisable to substitute it with a brand new textual content. Right here’s the way it works:

1. Enter the present frequent title within the “Present Textual content” area. Within the backside pane, you will note the frequent title get highlighted.

2. Within the “Exchange With” textual content field, enter the brand new frequent title you need to substitute the present title with.

3. Confirm the modifications within the backside pane and click on on “Rename” within the high proper nook to use the identical.

replace existing name with a new anme for all files

Utilizing GPRename to Rename Information

GPRename is a light-weight batch renaming device that comes with a number of completely different choices that may show helpful whereas renaming information utilizing the Linux GUI. This device will be useful for customers who discover it tough to batch rename information utilizing their native file supervisor. Sadly, it doesn’t come pre-installed, however can simply be put in utilizing the next instructions:

  • For Debian-based methods

sudo apt replace && sudo apt set up gprename

  • For Fedora-bassed methods

sudo dnf set up gprename

  • For Arch-based methods

sudo pacman -S gprename

Rename A Single File with GPRename

1. Open GPRename from the Purposes menu or sort gprename within the Linux Terminal.

2. Use the file system tree on the left to navigate to the specified folder. Then, choose the file you need to rename in the proper pane.

single file selected to rename in GPRename

3. Within the backside pane, choose the motion you want to take. For instance, if you wish to substitute a phrase within the file title with one other phrase, go to the “Exchange/ Take away” tab. Subsequent, enter the string you need to substitute within the “Exchange” textual content field and the brand new string within the “With” textual content field.

4. Confirm the modifications utilizing the “Preview” button on the proper. As soon as you might be glad, click on the “Rename” button beneath it.

Replace a part of file name using GPRename
Rename A number of Information with GPRename

1. As defined above, use the file system tree on the left to navigate to the specified folder. Then, choose the information you need to rename and select the suitable choice from the underside pane.

selecting multiple files in GPRename

2. To confirm the modifications, click on on the preview button on the proper and at last click on on the “Rename” button under it.

preview the changes before finally renaming the files

Incessantly Requested Questions

What does rm command do in Linux?

Despite the fact that the rm command might seem to be an acronym for rename, it stands for take away and is used to delete information and folders in Linux.

Simply Rename Information in Linux

As a newbie, it is very important perceive the nuances of file administration in Linux and renaming information is one thing you would possibly must do usually. On this information, we’ve proven you 4 strategies (2 CLI and a couple of GUI) to rename a single file and a number of information in a listing. Although the file supervisor will seemingly be the go-to for many Linux customers, the mv and rename instructions defined above are additionally broadly used for renaming information through the Terminal. Which of those strategies do you favor to rename information in Linux? Tell us within the feedback under.

#Rename #File #Linux #Strategies
#geekleap #geekleapnews

Leave a Reply

Your email address will not be published. Required fields are marked *