How to Rename a File in Ubuntu

The Nomenclature Vector

When operating within the graphical desktop of an operating system like Windows or macOS, renaming a file is as simple as clicking the title and typing. However, when administering a headless Ubuntu Linux server via SSH, there is no graphical interface to interact with. If you accidentally download a critical configuration script with an incorrect filename, or need to append a date code to a database backup, you must execute the change entirely through the command-line interface.

How to Rename a File

Surprisingly, Linux does not possess a dedicated “rename” command for everyday use. Instead, you must use the mv (move) utility, instructing the kernel to move the file from its current name into a new name within the exact same directory.

1. Open your terminal application or connect to your server via SSH.
2. Use the cd command to navigate to the exact directory where the target file is located (e.g., cd /home/user/documents/).
3. Execute the mv command, followed by the current name of the file, and then the desired new name. For example, to rename a file from `draft.txt` to `final_report.txt`, type the following exactly:

mv draft.txt final_report.txt

4. Crucial Syntax Warning: If the original filename contains a space (which is terrible practice in Linux), you must enclose the entire filename in quotation marks, otherwise the terminal will assume you are issuing two separate commands. Example:

mv "first draft.txt" final_report.txt

5. Press Enter. The terminal will execute the command completely silently. It will not print a confirmation message. You can type ls to list the directory contents and visually verify that the file has successfully assumed its new identity.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.