Renaming files in Linux is a very easy task that can be done with the following steps: Open up your favorite text editor (gedit, nano etc.) and create a new text file. In this text file you need to write out the name of the original filename you want to rename. Then add an extension at the end of it so that it’s easier to read later on when needing said information again.,
Introduction: Dogecoin was created as a “joke coin” meant to poke fun at bitcoin, but has since become one of Bitcoin’s chief competitors for market share. George Lagerwey founded DOGE Co-Founder Jackson Palmer believes cryptocurrency will have more impact than either tech or finance industries because people are increasingly accepting cryptocurrencies as less volatile investment options. Other notable cryptos include Litecoin (LTC) ZCash (), Ripple ().
The “rename multiple files in linux” is a command line tool that allows users to rename multiple files at once. The tool can also be used to create new directories and move files.
Do you have any experience with the Linux operating system? If this is the case, routine operations like renaming files and folders may vary from what you’re accustomed to. But don’t be concerned. Renaming files in Linux works similarly to renaming files in other operating systems.
You’ll learn how to rename single and many files in Linux using both the GUI and terminal commands in this article.
Let’s get this party started!
Make sure you have the following items in order to follow along with this tutorial:
Using File Manager to Rename Files
Let’s begin this lesson on renaming files using a file manager if you’re accustomed to handling files through GUI. GUI file managers are convenient because they allow you to view your files in plain sight. Nautilus, GNOME’s old file manager, is one of the file managers available in Linux. The Nautilus file manager is used to rename files in this tutorial.
Konqueror, Dolphin, Krusader, Thunar, Nemo file manager, and Sunflower file manager are some of the other Linux file managers. These file managers do the same thing, however the way they rename files or directories may vary somewhat.
If you don’t already have it on your system, open your terminal and type the command below to install Nautilus (install nautilus) using the apt package management. The sudo command grants sudo/administrator privileges to the command.
nautilus sudo apt install
Changing the Name of a Single File
Changing the Name of a Single File in Nautilus takes only a few clicks, like in Windows File Explorer.
To rename a single file, open Nautilus, right-click on the file you wish to rename, and choose Rename from the menu that appears, as shown below.
Although this example focuses on file renaming, the technique is the same for both files and directories.
Changing the Name of a Single File
Now input the new file name to replace the old one, hit Enter or click Rename, and you’re done.
Adding a New File Name
Using Nautilus File Manager to Rename Multiple Files
Ubuntu, like Windows, provides you additional choices for renaming numerous files at once.
To rename several files, select all of them, right-click on any of them, and pick Rename. A pop-up box will open, allowing you to choose how to rename the files you’ve chosen.
Using Nautilus to Rename Multiple Files
Depending on how you wish to rename the chosen files, there are two alternatives available below.
- Rename files using a template — You may rename files in increments using this method.
- Find and replace text — This feature allows you to search for and replace certain words in file names.
Using a Template to Rename Files
Select the Rename using a template option to rename files using a template.
To rename files using a template, type the replacement name in the empty area, then click the +Add button and choose a template from the drop-down menu. Select the first (1,2,3,4) and click Rename for this instruction. After the replacement filename (Text1, Text2,…), this option adds incrementing numbers to each file.
Using a Template to Rename Files
The file names have been converted to Text, and the numbers have been incremented.
Changing File Names to “Text” and Incrementing the Num
Words in File Names: Locating and Replacing
Select the Find and replace text option to rename several files with the same name.
Replace the content by typing the existing text in the Existing Text area and the new text in the Replace With field, then clicking Rename. This option searches for and substitutes certain words in file names.
Text Replacement in File Names
You can now notice that you’ve changed the term “Text” in each file name with “File” as seen below.
Verify that the word “Text” on each file has been changed with the term “File.”
Using the mv Command to Rename Files
Prepare to learn how to rename files in a terminal if you prefer using commands than browsing via a GUI. In the Linux terminal, renaming files is analogous to renaming files in other command-line systems, such as PowerShell. That’s all there is to it. You execute the instructions to rename the original file to the target file name, and that’s it.
When renaming a file, there are two possibilities. Renaming a file from the working directory is the first option, and giving the complete path is the second. To rename a file, use the mv command syntax below, where the source is the old name and the destination is the new name.
# Rename a file or directory in the working directory mv <source> <destination> # Rename a file by specifying the full path mv <~/mydir/source> <~/mydir/destination>
Changing the Name of a Single File with the mv Command
While the mv command syntax is still fresh in your mind, let’s try Changing the Name of a Single File.
To show how to rename a single file and directory, do the following:
To create a directory and two text files, first open your terminal and enter the instructions shown below.
# Change directory to /test cd test # Make a directory called ‘test’ mkdir test # Make two text files, file1.txt and file2.txt. touch file1.txt and file2.txt
2. Next, use the ls command to display a list of files in the current directory. The files file1.txt and file2.txt may be found in the /test directory, as shown below.
Files in the Working Directory are listed in alphabetical order.
3. Rename file1.txt to file10.txt using one of the mv commands below.
# mv file1.txt file10.txt rename a file in the working directory mv /test/file1.txt /test/file10.txt # Rename a file by supplying the complete path mv /test/file1.txt /test/file10.txt
Renaming a directory is similar to renaming a file, as in mv /test /demo. The home directory is indicated by the symbol.
4. To list the files in the working directory, execute the ls command.
File1.txt has been renamed to file10.txt, as seen below.
Verifying that file1.txt has been renamed to file10.txt
Using a For Loop to Rename Multiple Files
You’ll need to use a for loop expression like the one below if you’re too preoccupied with other duties and wish to rename all files at once.
Copy and paste the code below into your terminal, then press Enter. The code below checks the working directory for text files and renames them with “File” followed by an increasing number.
# Declares a variable with the value 1 i=1. # Scans each text file in the working directory for files ending in *.txt; # Repeat until all files have been scanned. # Renames each file with “File” before incrementing the number I mv — “$file” “File$i.txt” # Increases the current number value of the variables by 1 i=$((i+1)) done
It’s acceptable to paste the code into your terminal, but it’s best if you create a script file to execute instead.
Related: The Only Linux Shell Scripting Tutorial You’ll Ever Need
You can watch how the code renames all files in action in the video below.
Using a For Loop to Rename Files
Using the rename Utility in Linux to rename files
If you’re Changing the Name of a Single File in your daily routine, then the mv command will suffice. But perhaps you’re aiming to rename multiple files with the same pattern at once? For example, renaming files that start with a certain word (file). In that case, install the rename utility instead.
Multiple files may be renamed, file name formats can be changed, and files can be overwritten using the rename application.
Depending on the Linux distribution you’re using, use one of the instructions below to install the rename program.
# sudo apt install rename sudo apt install rename sudo apt install rename sudo apt install rename sudo apt install rename sudo apt install rename sudo apt install rename sudo apt install rename sudo # For CentOS, Fedora, and Red Hat, use the dnf package management to install the rename software sudo dnf install prename # pacman -S perl-rename sudo pacman -S perl-rename sudo pacman -S perl-rename sudo pacman -S perl-rename sudo pacman -S perl-rename sudo pacman -S perl-rename
The rename command syntax is shown below.
rename <options> <perlexpr> <files>
Multiple Files Renamed
With the rename command syntax in mind, you can now rename files that have the same pattern. What’s great about the rename command is that you don’t need to declare a loop function to rename multiple files as you did in the “Using a For Loop to Rename Multiple Files” section.
You may wish to rename files that include certain terms. Look at the Perl regular expression (‘s/file/myfile/’) in the example command below if that’s the case. Regular expressions in Perl are string patterns that are defined using the Perl programming language.
To prevent accidentally renaming other files, use the -n option to display all the affected files before renaming them, as shown below.
*.txt rename -n’s/file/myfile/’
Before renaming, make a list of the files that are affected.
Replace the word file with myfile in each text file’s name within the working directory or the /test/*.txt directory using one of the rename commands below.
The s implies substitution in the Perl phrase (‘s/file/myfile/’), which suggests you’re renaming files. The -v option is used to show which files were renamed by the operation.
# Replace ‘file’ with’myfile’ in the working directory’s file names rename -v’s/file/myfile/’ *.txt # rename -v’s/file/myfile/’ /test/*.txt rename -v’s/file/myfile/’ /test/*.txt rename -v’s/file/myfile/’ /test/*.txt rename -v’s/file/myfile/’ /test/*.txt rename -v ‘
Each “file” term in the text files has been renamed to “myfile,” as seen below.
Using the rename Command to rename a file
Remove the file extension when specifying the file path, for example, rename -v’s/file/myfile/’ /test/* if you desire to rename all files.
Modifying the File Extensions
The rename command also renames file extensions in addition to file names. It’s possible that you produced files with the incorrect file extension. When you use the rename command, you’ll provide the file extension to modify in a Perl expression.
Run the rename command below to change all files’ (*) extension from .txt to .html in the ~/test directory. The $ symbol in the Perl expression matches the end of a string (.txt) to each file name, so the command only changes .txt file extensions. And like with Multiple Files Renamed, add the -v option to list each change the command makes.
*.txt rename -v’s/.txt$/.html/’
Delete the replacement string in the Perl phrase like this to remove all file extensions: *.txt rename -v’s/.txt$/’
The.txt extensions have been replaced with.html, as seen in the figure below.
Modifying the File Extensions from .txt to .html
Changing Uppercase and Lowercase File Names
You can be dealing with filenames in lowercase instead of erroneous file extensions, and vice versa. Perhaps you’re looking for a file in uppercase but don’t realize the file name is in lowercase.
Because Linux is case-sensitive, double-check that the letter case of each file name is correct. The contrast between lowercase and uppercase letters is known as letter case.
How to Use the Bash Find Command to Find Files Using Dozens of Criteria
To convert all lowercase (a-z) file names in the working directory (*) to uppercase (A-Z), use one of the rename commands below.
# rename -v ‘y/a-z/A-Z/’ rename -v ‘y/a-z/A-Z/’ rename -v ‘y/a-z/A-Z/’ rename -v ‘y # rename -v ‘y/A-Z/a-z/’ rename -v ‘y/A-Z/a-z/’ rename -v ‘y/A-Z/a-z/’ rename -v ‘y
Both the outcomes of altering the letter case of a file name are seen below.
Changing the case of a file name from lower to uppercase and vice versa
Spaces in File Names are Replaced and Removed
You may have problems discovering files if they include spaces in their file names, similar to how letter case affects file names. Let’s solve it by either substituting a character for the spaces or deleting the gaps entirely.
Replace spaces in all file names in the working directory with an underscore (_) using the rename command. Because underscore is a metacharacter, it must be declared literally by escaping it with a backslash ( ). Metacharacters are special characters in a computer program that have unique semantics.
The g in the Perl phrase indicates that the command should replace all matches (spaces), not just the first.
The command replaced all spaces with underscores, as seen below.
In a file name, replacing spaces with underscores
Run the command below to eliminate all spaces from a file name rather than filling them with a character.
The asterisk following the blank space (/ *) in the Perl expression below matches all occurrences of spaces in a file name, not just the first one. The rename command eliminates all (g) spaces since the replacement character is empty (/).
As you can see in the screenshot below, all spaces have been eliminated from each file name.
Delete all spaces from filenames
In a file name, capitalize the first letter of each word
You’ll need a more complicated Perl expression if you want to maintain the spaces and capitalize the first letter of each word in a file name instead. Take a look at the command below for an example.
The Perl expression below matches any single character (\w) in a word boundary (\b) so long as the character is not a period nor apostrophe (?<![.’\”]). The rename command will then translate that letter to uppercase (u$&).
rename -v ‘s/(?<![.’\”])\b\w*/\u$&/g’ *
Each word in the file names begins with a capital letter, but the file extensions are unaffected.
In file names, capitalize the first letter of each word
You’ve learnt how to rename Linux files using the GUI and the command-line terminal throughout this lesson. You now have a firm grasp on how to change the names of single and many files at the same time.
Why not learn Linux shell scripting and write a script to rename files in Linux automatically?
The “rename file command line” is a command-line tool that allows users to rename files in Linux. The “rename file” command can be used to rename multiple files at once, or it can be used with wildcards.
Frequently Asked Questions
How do you rename a file in Linux?
A: Rename is a command that changes the name of an existing file. This can be easily done by typing ren followed by any number or letter to change the first character in the filename, and then pressing TAB or ENTER to switch between letters. If you want to remove characters from your filenames, use mv.
How do you rename a file?
A: Rename is a command that changes the name of a file. You can use it to change the extension or add other things like date, location and even your username into it.
How do I rename a file in terminal?
A: Rename a file in terminal by typing the desired name of your new file, followed by .new at the end. For example to rename file1 for file2, type
- linux rename command examples
- rename file in unix
- rename multiple files in linux using for loop
- bash rename file
- copy and rename file linux