The mv
command is used to move or rename files and directories in Unix/Linux operating systems. Here are some examples of how to use the mv
command:
- To rename a file:
mv oldfile newfile
This will rename the file
oldfile
tonewfile
. - To move a file to a different directory:
mv file /path/to/directory/
This will move the file
file
to the directory/path/to/directory/
. - To move multiple files to a different directory:
mv file1 file2 file3 /path/to/directory/
This will move the files
file1
,file2
, andfile3
to the directory/path/to/directory/
. - To move a directory:
mv directory /path/to/directory/
This will move the directory
directory
to the directory/path/to/directory/
. - To move and rename a file at the same time:
mv oldfile /path/to/directory/newfile
This will move the file
oldfile
to the directory/path/to/directory/
and rename it tonewfile
. - To move and rename a directory at the same time:
mv olddirectory /path/to/directory/newdirectory
This will move the directory
olddirectory
to the directory/path/to/directory/
and rename it tonewdirectory
.