Mv (Unix)

Z Multimediaexpo.cz

mv (zkratka pro move) je příkaz v UNIXu a odvozených systémech používaný pro přesun souborů.

Chování

Po přesunutí souboru je již nedostupný pod svým původním jménem v původním adresáři. Je-li za cílový soubor zvolen soubor existující, je nenávratně přepsán.

Pro přesunutí je potřeba mít práva pro zápis pro všechny modifikované adresáře.

Příklady použití

 mv myfile mynewfilename     # renames 'myfile' to 'mynewfilename'.
 mv myfile ~/myfile          # moves 'myfile' from the current directory to user's home directory.
 mv myfile subdir/myfile     # moves 'myfile' to 'subdir/myfile' relative to the current directory.
 mv myfile subdir            # same as the previous command, filename is implied to be the same.
 mv myfile subdir/myfile2    # moves 'myfile' to 'subdir' named  'myfile2'.
 mv be.03 /mnt/bkup/bes      # copies 'be.03' to the mounted volume 'bkup' the 'bes' directory, 
                             # then 'be.03' is removed.
 mv afile another /home/yourdir/yourfile mydir 
                             # moves multiple files to directory 'mydir'.
 mv -v Jun* bkup/06          # displays each filename as it is moved to the subdirectory 'bkup/06'.
 mv /var/log/*z ~/logs       # takes longer than expected if '/var' is on a different file system, 
                             # as it frequently is, since files will be copied & deleted.
 
 mv --help                   # shows a concise help about the syntax of the command.
 mv !(bkup) bkup             # mv all files and dirs to the dir in the same level
                             # move "all the files and directories"(except bkup) to the "bkup" directory,
                             # (assuming , if "all the files and directories" and "bkup" directory are in the same directory )
 mv !(bkup1|bkup2) bkup2     # move  "all the files and directories"(except bkup1, bkup2) to the "bkup2" directory.
 man mv                      # displays complete manual for mv.