UNIX mv Command Examples

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:

  1. To rename a file:
    mv oldfile newfile

    This will rename the file oldfile to newfile.

  2. 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/.

  3. To move multiple files to a different directory:
    mv file1 file2 file3 /path/to/directory/

    This will move the files file1, file2, and file3 to the directory /path/to/directory/.

  4. To move a directory:
    mv directory /path/to/directory/

    This will move the directory directory to the directory /path/to/directory/.

  5. 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 to newfile.

  6. 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 to newdirectory.

Leave a Comment