How to Change a Filename in Linux
In this tutorial, we will take you through the steps of changing a file name in Linux using the command line. You can do this in several ways, and we will take you through the two most popular methods. Both are super easy. There are a few different methods that you can use to change a filename on a Linux system. However, we will be focusing on using the mv and rename commands. Both of these commands are easy to use.
For this tutorial, we will be focusing purely on the terminal.
Getting started with Linux? Try a Raspberry Pi!
Using the mv Command to Change a Filename
One of the easiest ways to change a filename is to use the mv command. This command is normally used for moving a file or directory but can also rename files and directories.
Below is an example of the syntax for rewriting a file using the mv command.
mv old_file_name new_file_name
Below is an example of renaming our index.html
file to backend.php
.
mv index.html backend.php
You can confirm that the filename has been updated using the ls command.
dev@pimylifeup:~/test$ mv index.html backend.php
dev@pimylifeup:~/test$ ls
backend.php
You can also do the same with a directory using the same logic. The example below will rename our www
directory to html
.
mv www html
Again, you can use the ls command to check that the directory’s name has been updated correctly.
dev@pimylifeup:~/test$ ls
www
dev@pimylifeup:~/test$ mv www html
dev@pimylifeup:~/test$ ls
html
The post How to Change a Filename in Linux appeared first on Pi My Life Up.