mv is a file management utility used to move or rename files and directories. It is a versatile tool that allows you to rename, move, or even merge files and directories.
Basic Syntax
mv [options] source destination
Here, source specifies the file or directory to be moved, and destination specifies the new name or location of the file or directory. If destination is a directory, the source file or directory is moved into the directory.
Commonly Used Options
-
-i: This prompts the user for confirmation before overwriting an existing file. -
-f: This forces the move of a file or directory without prompting for confirmation, and overwrites an existing file with the same name in the destination directory. -
-v: This displays the progress of the move operation, including the source and destination files or directories.
Useful Examples
-
mv file1.txt file2.txt: This renamesfile1.txttofile2.txt. -
mv file.txt /home/user/directory: This movesfile.txtto the/home/user/directorydirectory. -
mv file.txt dir/: This movesfile.txtinto thedirdirectory. -
mv file.txt dir/file2.txt: This renamesfile.txttofile2.txtand moves it into thedirdirectory. -
mv -i file.txt dir/file.txt: This movesfile.txtinto thedirdirectory and prompts the user for confirmation if a file with the same name already exists in the destination directory. -
mv -f file.txt dir/file.txt: This movesfile.txtinto thedirdirectory and overwrites any existing file with the same name in the destination directory without prompting for confirmation. -
mv -v file.txt dir/file.txt: This movesfile.txtinto thedirdirectory and displays the progress of the move operation.
Leave a Reply