Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
mv SOURCE TARGET moves a file or folder. If the target is a new name in the same folder, it is a rename. Inside one file system, mv only changes the name, so even huge files move in an instant. Between file systems it copies the data and then deletes the source.
A moved file keeps its permissions, owner and SELinux label. That is a classic problem when you move files into /var/www/html: run restorecon after.
Zo schrijf je het
mv [OPTION]... SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...Opties 17
Meest gebruikt
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Rename a file
mv report.txt report-2026.txtSame folder, new name.
2Move files into a folder
mv *.log /var/log/archive/All matching files go into the folder.
3Move and fix the SELinux label at once
mv -Z /tmp/index.html /var/www/html/Without -Z the file keeps the
user_tmp_tlabel and Apache shows "403 Forbidden".4Ask before overwriting
mv -i new.conf /etc/myapp/app.confSafe when the target may exist.
5Do not overwrite existing files
mv -n uploads/* /srv/files/Files that already exist in the target stay as they are.
6Rename a folder
mv /srv/app-old /srv/app-2025Folders need no -r for mv.
7Replace a config file atomically
cp app.conf /etc/myapp/app.conf.new && mv /etc/myapp/app.conf.new /etc/myapp/app.confOn the same file system the rename is atomic: a reader sees the old or the new file, never half of it.
8Switch a release with a symlink (zero downtime deploy)
ln -sfn /srv/app/releases/42 /srv/app/current.tmp && mv -T /srv/app/current.tmp /srv/app/currentmv -Treplaces the link in one atomic step.9Keep a backup of the file you overwrite
mv --backup=numbered new.cfg app.cfgThe old app.cfg becomes app.cfg.~1~.
10Move many files given by find
find /tmp -maxdepth 1 -name "*.csv" -mtime +7 -exec mv -t /archive/ {} +-tmakes it easy to use with find and xargs.11Show each move
mv -v *.jpg photos/Prints "renamed 'a.jpg' -> 'photos/a.jpg'".
Niets past bij dit filter.
Let op
mvoverwrites without asking (normal users). Use-ior-n.- Moved files keep their old SELinux label. Use
mv -Zor runrestorecon -Rvon the new place. - A typo in the target can rename instead of move:
mv file /backpcreates a file named /backp.
Tips om te onthouden
- Same folder = rename. Other folder = move.
-Z= new place, new SELinux label.