Glossary

mv

mv renames a file when source and destination are on the same filesystem (a cheap directory-entry update), and physically copies-then-deletes when they cross filesystems. Both cases look the same to the user.

mv old.txt new.txt               # rename
mv file.txt archive/             # move into directory
mv -i a.txt b.txt                # prompt before overwriting
mv -n a.txt b.txt                # never overwrite
mv *.log logs/                   # move all matching files

Unlike cp, mv does not have a recursive flag: directories are moved atomically within a filesystem regardless of their contents. Across filesystems, mv uses the equivalent of cp -r && rm -r internally, so it can be slow for large trees.

Related terms: cp, rm, rename

Discussed in:

Textbook of Linux — Learn Linux on iPhone — Download on the App Store