The mv
command in Bash is used to move or rename files and directories. It allows users to change the location of a file or folder, or to give it a new name within the same directory.
The basic syntax of the mv
command is as follows:
mv [options] [source] [destination]
-i
: Prompts before overwriting an existing file.-u
: Moves only when the source file is newer than the destination file or when the destination file does not exist.-v
: Verbose mode; shows what is being done.-n
: No overwrite; does not overwrite an existing file.mv myfile.txt /home/user/documents/
mv oldname.txt newname.txt
mv myfile.txt /home/user/documents/newfile.txt
mv file1.txt file2.txt /home/user/documents/
mv -i myfile.txt /home/user/documents/
-i
option if you are unsure about overwriting files, as it helps prevent accidental data loss.-v
to see a detailed output of the operation, which can be helpful for tracking what files are being moved or renamed.mv
may copy and then delete the original file, which can take longer than moving files within the same file system.