mv Linux Command
mv Linux Command
The mv Linux command moves files and directories from one place to another on the Linux system. If both the source and destination are on the same filesystem, this command can even simulate renaming.
Syntax
The general syntax of the command is as follows:
$ mv <source> <destination>
- <source>: The file or directory you want to move.
- <destination>: The new location or the new name for the source file/directory
Example
Move a file to another location
$ sudo mv jdk16 /opt/jdk
Here in this example, we are moving the jdk16 directory contents to /opt/jdk. The source is jdk16 directory. The destination is /opt/jdk
To know more about the command, visit the man page.
$ man mv
In the example, we have also used the sudo command. To know more about sudo command:
Another Example
$ mv tdocs.txt /home/testingdocs/Documents/
The above command moves tdocs.txt
to the /home/testingdocs/Documents/
directory.
Renaming a File
You can also rename a file by moving it to a new file name in the same directory:
$ mv oldname.txt newname.txt
Using Wildcards
You can move multiple files using wildcards (*), for example:
mv *.txt /path/to/destination/
This moves all .txt files from the current directory to the destination directory.
Overwriting Without Prompting (Force Option)
If the destination already exists, the mv command will overwrite the destination file without asking. To prevent this and prompt for confirmation, use the -i (interactive) option:
$ mv -i file.txt /path/to/destination/
To forcefully overwrite without being prompted, use the -f (force) option:
$ mv -f file.txt /path/to/destination/
Linux Commands
Linux Basic Commands Tutorial page:
More Information on Ubuntu Linux:
- https://ubuntu.com/