mv command in Linux with examples
mv stands for move. mv is used to move one or more files or directories from one place to another in a file system like UNIX. It has two distinct functions:
(i) It renames a file or folder.
(ii) It moves a group of files to a different directory.
No additional space is consumed on a disk during renaming. This command normally works silently means no prompt for confirmation.
mv [Option] source destination
Let us consider 4 files having names a.txt, b.txt, and so on till d.txt.
To rename the file a.txt to geek.txt(not exist):
$ ls a.txt b.txt c.txt d.txt $ mv a.txt geek.txt $ ls b.txt c.txt d.txt geek.txt
If the destination file doesn’t exist, it will be created. In the above command mv simply replaces the source filename in the directory with the destination filename(new name). If the destination file exist, then it will be overwrite and the source file will be deleted. By default, mv doesn’t prompt for overwriting the existing file, So be careful !!
Let’s try to understand with an example, moving geeks.txt to b.txt(exist):