Renaming a file is a basic operation in any operating system. Files can be renamed in multiple ways in Linux. The task can be achieved using GUI or command-line. Moreover, advanced utilities can also be used to rename these files. All these ways are documented in this article in a way that is easy to follow.
- Ubuntu 20.04 system
- User with sudo privileges for renaming multiple files.
Note: The commands discussed in this article have been tested on Ubuntu 20.04 LTS (Focal Fossa).
Method # 1: Renaming files using GUI
We will be renaming a file named file.txt.
Right-click on the file that needs to be renamed. A menu appears on the screen.
Click on the rename. The name of the file will become editable.
Write the name of the new file and press enter.
The file will be renamed.
Method # 2: Renaming files using mv command
mv command has the following syntax.
mv [source] [destination]
Right-click in the folder where the file to be renamed is present.
Click on open in terminal to open the directory in command line.
We will use mv utility to move files. The file name file.txt can be renamed to document.txt using the following command:
$ mv file.txt document.txt
The file can be checked to have renamed. Run the following command in terminal:
Method # 3: Renaming multiple files using rename command
Run the following command on the terminal to install rename utility.
$ sudo apt install rename -y
We will be renaming multiple files in txt files to md files. The name or corresponding text file will remain name when it’s extension is moved to markdown. We have three text files as the following image suggests.
Run the following command in terminal for renaming all these files:
$ rename ‘s/\.txt$/\.md/’ *.txt
- ‘s/\.txt$/\.md/’ – Substitute .txt in place of .md.
- *.txt – Apply the operation on name of all the files.
The files can be checked to have renamed by using the following command:
In this article, we have explored how to rename a file using GUI as well as command-line. Moreover, a utility has also been explored to rename multiple files at once. We hope you can easily rename files and folders in Linux after following this article.