How to Rename Files in Ubuntu 20.04

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.

Prerequisites

  • 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.

C:\Users\Muhammad Usman\Downloads\mv\mv.png

Right-click on the file that needs to be renamed. A menu appears on the screen.

C:\Users\Muhammad Usman\Downloads\mv\mv4.png

Click on the rename. The name of the file will become editable.

C:\Users\Muhammad Usman\Downloads\mv\mv5.png

Write the name of the new file and press enter.

C:\Users\Muhammad Usman\Downloads\mv\mv6.png

The file will be renamed.

C:\Users\Muhammad Usman\Downloads\mv\mv7.png

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.

C:\Users\Muhammad Usman\Downloads\mv\mvv.png

Click on open in terminal to open the directory in command line.

C:\Users\Muhammad Usman\Downloads\mv\mv0.png

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

C:\Users\Muhammad Usman\Downloads\mv\mv1.png

The file can be checked to have renamed. Run the following command in terminal:

$ ls

C:\Users\Muhammad Usman\Downloads\mv\mv2.png

Method # 3: Renaming multiple files using rename command

Run the following command on the terminal to install rename utility.

$ sudo apt install rename -y

C:\Users\Muhammad Usman\Downloads\mv\mv8.png

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.

C:\Users\Muhammad Usman\Downloads\mv\mv10.png
Run the following command in terminal for renaming all these files:

$ rename ‘s/\.txt$/\.md/’ *.txt

C:\Users\Muhammad Usman\Downloads\mv\mv12.png

  • ‘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:

$ ls

C:\Users\Muhammad Usman\Downloads\mv\mv13.png

Conclusion

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.