Renaming files in Linux is a fundamental skill that every user should master. Whether you want to give a more meaningful name to a file or correct a typo in a filename, Linux offers several methods to accomplish this task.
In this article, I have explained 5 ways to rename files in Linux with easy-to-follow examples.
How to rename a file in Linux
There are three ways using the bash command and two ways using GUI to rename files in the Linux file system.
Method 1: Using the “mv” Command
mv (move) command is a versatile tool that can also be used to rename files. To rename a file using
mv. To rename file open your Linux terminal and use the following syntax:
mv old_filename new_filename
old_filename with the current name of the file and
new_filename with the desired new name. For example, if you want to rename a file called “file1.txt” to “newfile.txt,” you would enter:
mv file1.txt newfile.txt
This command will rename the file.
Method 2: Renaming Files with the “rename” Command
rename command is a powerful tool for batch renaming files based on patterns. To rename a single file using
rename, use the following syntax:
rename 's/old_filename/new_filename/' file_to_rename
Here’s an example:
rename 's/file1/newfile/' file1.txt
This command will rename “file1.txt” to “newfile.txt.”
Method 3: Using the GUI
Most Linux desktop environments provide a graphical way to rename files. Here’s how you can do it in GNOME, one of the popular Linux desktops:
- Open the file manager (e.g., Nautilus).
- Locate the file you want to rename.
- Right-click on the file and select “Rename.”
- Type in the new name and press Enter.
Method 4: Renaming with Tab Completion
Tab completion is a handy feature in the Linux terminal that can make file renaming quicker. Here’s how it works:
- Start typing the
mvcommand followed by the first few letters of the old filename.
- Press the Tab key. Linux will autocomplete the filename.
- Modify the autocompleted name to the new filename.
- Press Enter to execute the command.
Method 5: Renaming with Midnight Commander
If you prefer a file manager in the terminal, Midnight Commander (MC) is a great option. Follow these steps to rename a file with MC:
- Open your terminal and run
mcto launch Midnight Commander.
- Navigate to the directory containing the file you want to rename.
- Select the file by highlighting it.
- Press the F6 key or select the “Rename” option from the menu.
- Enter the new name and press Enter.
These methods should cover most scenarios for renaming files in Linux. Choose the one that suits your needs and workflow the best.
Quick Tips for File Renaming in Linux
Here are some quick tips to keep in mind:
|Backup your files
|Before renaming, make a backup in case something goes wrong.
|Use meaningful names
|Choose descriptive names to easily identify files.
|Be cautious with “
mv” command can also move files if used incorrectly. Be careful!
|Use tab completion for efficiency
|Tab completion can save you time when typing long filenames.
|Batch rename with
|If you need to rename multiple files, consider using “