How to Move & Rename Files in Linux
In this article we are knowing how to rename and move a files or directories in linux operating system. We are doing all this with the help of command ‘mv’.
The mv is a Linux command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified.
Use the mv command
- Moves a file (i.e. gives it a different name).
- Rename a file.
You need to use the mv command to rename a file as follows
- mv old-file-name new-file-name
- mv file1 file2
- mv source target
- mv [options] source target
Note : Bold characters are command & words in Italics are source and target used in commands.
After knowing about basic syntax and working of this command we are practice some examples:
Open the terminal (bash shell prompt) and type the following command to list file names:
#ls #ls -l
In this example, rename a file called data.txt to letters.txt, enter:
#mv data.txt meta.txt
File is renamed so the following command will display an error on screen:
# ls -l meta.txt ls: cannot access data.txt: No such file or directory
The following would rename a file called too to fro, while keeping it in the current directory:
#mv too fro
Rename a directory/folder Linux command
The following would rename a directory (folder) called dir1 to dir2, while keeping it in the current directory:
#mv dir1 dir2
Move a file/folder to an existing directory
The following would move a file named rest.txt, without changing its name, to an existing subdirectory called /home/Ready/Documents/
#mv rest.txt /home/Ready/Documents/
after that for verifying we are using ls -l
#ls -l /home/Ready/documents
from all this commands we are know hoe to rename & move, files & directories in the linux operating system.