mv: Move or rename files and directories
August 9th, 2024 8:59 AM Mr. Q Categories: Command
Command: mv
Used to move or rename files and directories, including the ability to move directories and their contents recursively.
Sample Command and Output:
$ mv file1.txt /home/user/Documents/
$ ls /home/user/Documents/
file1.txt
Description:
mv file1.txt /home/user/Documents/: Movesfile1.txtfrom the current directory to/home/user/Documents/.ls /home/user/Documents/: Lists the contents of the destination directory to confirm thatfile1.txthas been moved.
Sample Command and Output:
$ mv file1.txt file2.txt
$ ls
file2.txt
Description:
mv file1.txt file2.txt: Renamesfile1.txttofile2.txtin the current directory.ls: Lists the contents of the current directory to confirm thatfile1.txthas been renamed tofile2.txt.
Sample Command and Output:
$ mv -r folder1/ /home/user/Backup/
$ ls /home/user/Backup/
folder1
Description:
mv -r folder1/ /home/user/Backup/: Moves the directoryfolder1and its contents recursively to/home/user/Backup/. The-roption indicates recursive operation, though it’s worth noting thatmvhandles directories by default without needing-r.ls /home/user/Backup/: Lists the contents of the destination directory to confirm thatfolder1has been moved.
Additional Argument:
-i: Prompts before overwriting files.-f: Forces the move, overwriting files without prompting.-v: Verbose mode, displays the files being moved.
Sample Command and Output:
$ mv -v file1.txt /home/user/Documents/
renamed 'file1.txt' -> '/home/user/Documents/file1.txt'
Description:
mv -v file1.txt /home/user/Documents/: Movesfile1.txtto/home/user/Documents/and displays the move operation with a message indicating the file rename action. The-voption is used to provide verbose output.