mv (Unix)

from Wikipedia, the free encyclopedia

mv ( engl. abbreviation for m o v e) is a UNIX command which one or more files or directories shifts from one place to another.

use

The syntax of mv works analogously to cp(1):

mv quelldatei zieldatei

Several files can be moved to a target directory at the same time:

mv quelldateien ... zielverzeichnis

function

Moving takes place transparently for the user: it is independent of whether the source and destination are on different file systems or not. If all specified names are on the same partition , only the corresponding entries in the directory inodes are changed. No further data blocks need to be moved.

If, however, the goal on another file system mounted , the originating data blocks are actually copied, and then in the output directories in accordance rm(1)with unlink(2)distance.

For these reasons, writing rights are required in both the source and target directories to move files .

Conflicts with existing target files

If a file is moved to a file name of an existing file, the latter will be deleted. If there are no write permissions for the existing target file, but for the directory of the target file, mv asks interactively whether it should overwrite the file if the -f (for f orce) parameter is not set:

$ ls -l
insgesamt 0
-rw-r--r-- 1 sven users  0 22. Apr 22:51 a.txt
drwxr-xr-x 2 sven users 72 22. Apr 22:51 ziel

$ ls -l ziel/
insgesamt 0
-r--r--r-- 1 sven users 0 22. Apr 22:51 a.txt

$ mv a.txt ziel
mv: Überschreiben von »ziel/a.txt«, über Modus 0444 hinwegsetzen?

Delimitation for copying and deleting files

It should be noted that usually moving files within the same file system is not the same as copying that file and then deleting the original. When moving a file on the same file system in Unix file systems, the hard link of the file is simply removed from the source directory and a new one is added to the target directory. The file (the inode ) itself remains unaffected, i.e. H. the inode and thus the position of the file on the storage medium does not change.

This relationship also explains the relationship between the file rights : You cannot copy a file to which you have no read access, but you can move it (provided you have write rights in the original and target directory, see above). The way of thinking is analogous with directories: Let there be a directory filled with files, to whose files you have no write access. Accordingly, the directory must not be deleted because the authorization to delete the contents is missing. Nevertheless, you can move the directory yourself.

See also

Web links

Wikibooks: Linux-Praxisbuch: mv  - learning and teaching materials