mv Command

Rename source to destination, or move source to directory.

Basic Usage:
mv source target

Examples:
mv aaa.txt bbb.txt
We open termainal at aaa.txt path.
aaa.txt filename changes as bbb.txt with above command.
If already there is bbb.txt file in directory, aaa.txt overrides its.

mv bbb ccc
bbb folder name changes as ccc and its content saves. If already there is ccc folder, bbb moves to inside of ccc folder, except there is a bbb which isn't empty folder in ccc.

mv bbb /home/user
bbb folder moves to inside of /home/user folder.

mv /home/user/belgeler/bbb /home/user/dosyalar/ccc ddd /home/user
bbb,ccc and ddd folders with contents moves to /home/user/ folder.

mv aaa.txt ../
aaa.txt file moves to one up folder, if it is not in root.

mv ccc.txt ~/documents
ccc.txt file moves to user's documents folder in home folder. ~ signs user's home folder.

mv !(aaa1) aaa1
All files and folders in current directory except aaa1 folder moves aaa1 folder.

mv !(aa|bb|cc) aa
All files and folders except aa,bb and cc folders moves to aa folder.

mv * ../aaa1
All files and folders moves to aaa1 folder which is one level up folder.

mv *.txt ??a? -v
All txt extended files in current directory moves to directory third character is a and has four characters and displays process on screen. If there are folders with their names ends with .txt, moves too.

mv --backup=numbered source target
source folder moves to inside of target folder and old source named file in target folder saves as source.~1~. Every moving increases the number of extended name and all old files saves.

mv --backup=simple source.txt /target
old source.txt file saves source.txt~ as standart. You can change extended name with --suffix parameter.

mv -i bbb.txt asa/bbb.txt
-i or --interactive parameter asks for before overriding.
It asks for bbb.txt file moves and overrides bbb.txt in asa folder and acts as answer.

mv --suffix=.bak aaa.txt bbb.txt veya mv -S .bak aaa.txt bbb.txt
--suffix=SUFFIX or -S SUFFIX parameter, override the usual backup suffix.
bbb.txt file back up as bbb.txt.bak and aaa.txt overrides bbb.txt. If there is a register like bbb.txt.~4~ or similar, suffix will be as bbb.txt~5~ or similar, not as .bak.

mv --backup=simple --suffix=.bak 111.txt aa
It saves as 111.txt.bak in aa folder.

mv --backup=t --suffix=.bak 222.txt 333.txt
Saving as 333.txt.~1~. --suffix parameter isn't effective for this command.

mv -t bbb ccc ddd
mv ccc -t bbb ddd
-t or --target-directory=DIRECTORY parameter defines the target directory. Target directory is folder which places after -t parameter.
ccc and ddd folders move to inside of bbb folder for two commands.

mv -T bbb ccc
-T and --no-target-directory parameter treats destination as a normal file.
When this command applies, file and folders in bbb moves to in ccc folder and it removes bb folder. If ccc folder isn't empty, it fails. If already there isn't ccc folder, it changes only name from bbb to ccc.

mv -T bbb.txt ccc.txt
bbb.txt dosyasının içeriği ccc.txt dosyası içerisine yazılır. ccc.txt dosyasında önceki içerik silinir. ccc.txt dosyası yoksa sadece isim değişikliği olur.

mv -u bbb.txt asa/bbb.txt
-u or --update parameter moves only when the source file is newer than the destination file or when the destination file is missing
If bbb.txt in asa folder is newer than source, it can't move for this command.

mv -v bbb.txt asa/bbb.txt
-v or --verbose parameter gives order "explain what is being done".
If moving finishes successfully, it gives a message to screen: `bbb.txt' -> `asa/bbb.txt'. If it fails there isn' warning.

mv --help
Display help screen.

mv --version
Display output version information.



Above process applied on "GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)"
Date of Article: 10.03.2016




HOME GNU/LINUX Commands TURKISH