Skip to Sidebar Skip to Content

How to Rename a File on Linux

Join 1M+ Learners

Learn & Practice DevOps, Cloud, AI, and Much More — All Through Hands-On, Interactive Labs!

Create Your Free Account BLACK FRIDAY SALE: Up to 50% OFF On Annual Plans
How to Rename a File on Linux

The command to rename a file on Linux-based operating systems is:

mv old_name new_name

That's if the file is located in our current directory. Not in the current directory? Then we first have to "move" there with the cd command.

Here's a real example.

Let's say our files are in the following directory path: /home/alex/projects/project1/. First, we should switch to the project1 directory located at that path:

cd /home/alex/projects/project1/

Then we can list our directory contents with the ls command:

ls

Finally, to rename file5.html to index.html, we can run this command:

mv file5.html index.html

If we list our directory contents again, we can see the file was renamed:

This wraps up the most basic use case of the mv command.

Also want to know how to move, copy, or delete files and directories? Then check out our blog about how to manage files and directories on Linux.

Alexandru Andrei Alexandru Andrei
You can find Alexandru's tutorials on DigitalOcean, Linode, Alibaba Cloud. He believes the Linux ecosystem is simple, elegant, and beautiful. He's on a mission to help others discover this Linux world.

Subscribe to Newsletter

Join me on this exciting journey as we explore the boundless world of web design together.