Computer Science Atlas
Tutorial

How to Rename a File in Ubuntu

February 3, 2021
 

Step 1. Open a Terminal Session

If you're using an Ubuntu laptop or desktop, you can press Ctrl + Alt + T on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.

Step 2. Use mv

Simple Rename

The mv command (short for "move") allows you to rename a file. For example, to rename a file called existing.html to new.html, you can run:

Bash
Copy
mv existing.html new.html
$
mv existing.html new.html

The general syntax for the command is:

Out
Copy
mv <existing filename> <new filename>
mv <existing filename> <new filename>

Move To New Directory

As its name implies, the command also allows you to move a file from one directory to another. For example, if we have a file in directory /var/www/html/ called existing.html that we want to move to /home/ubuntu/, we can run:

Bash
Copy
mv /var/www/html/existing.html /home/ubuntu/
$
mv /var/www/html/existing.html /home/ubuntu/

After this command, the file will now be located at /home/ubuntu/existing.html and /var/www/html/existing.html will no longer exist.

Rename While Moving

You can also rename a file while simultaneously moving it from one directory to another. If, in the previous example, you want to rename the file to new.html in the move to /home/ubuntu/, you can just specify the new filename in the second argument to the command:

Bash
Copy
mv /var/www/html/existing.html /home/ubuntu/new.html
$
mv /var/www/html/existing.html /home/ubuntu/new.html

After this command, the file will now be located at /home/ubuntu/new.html and /var/www/html/existing.html will no longer exist.