الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

mv

Move files and folders, or rename them.

المستوى
امتحان RHCSA
المجموعة
الملفات والمجلدات
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

mv [OPTION]... SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...

الخيارات 17

الأكثر استخدامًا

-i, --interactive
Ask before overwriting a file.
-f, --force
Do not ask before overwriting.
-n, --no-clobber
Never overwrite an existing file.
-u
Move only when the source is newer than the target, or the target is missing.
--update[=<which>]
Control which existing files are replaced: all, none, none-fail, older.
-v, --verbose
Print each move.
-t, --target-directory=dir
Move all sources into this folder.
-T, --no-target-directory
Treat the target as a normal file, never as a folder.
--backup[=<control>]
Make a backup of each target that would be overwritten.
-b
Like --backup without an argument.
-S, --suffix=suffix
The ending of backup files (default ~).
--no-copy
Do not copy when renaming fails (when the target is on another file system).
--strip-trailing-slashes
Remove the slash at the end of each source.
-Z, --context
Give the moved file the default SELinux context of its new place.
--debug
Explain how each file is moved (implies -v).
--help
Show help.
--version
Show the version.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Rename a file

    mv report.txt report-2026.txt

    Same folder, new name.

  2. 2Move files into a folder

    mv *.log /var/log/archive/

    All matching files go into the folder.

  3. 3Move and fix the SELinux label at once

    mv -Z /tmp/index.html /var/www/html/

    Without -Z the file keeps the user_tmp_t label and Apache shows "403 Forbidden".

  4. 4Ask before overwriting

    mv -i new.conf /etc/myapp/app.conf

    Safe when the target may exist.

  5. 5Do not overwrite existing files

    mv -n uploads/* /srv/files/

    Files that already exist in the target stay as they are.

  6. 6Rename a folder

    mv /srv/app-old /srv/app-2025

    Folders need no -r for mv.

  7. 7Replace a config file atomically

    cp app.conf /etc/myapp/app.conf.new && mv /etc/myapp/app.conf.new /etc/myapp/app.conf

    On the same file system the rename is atomic: a reader sees the old or the new file, never half of it.

  8. 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/current

    mv -T replaces the link in one atomic step.

  9. 9Keep a backup of the file you overwrite

    mv --backup=numbered new.cfg app.cfg

    The old app.cfg becomes app.cfg.~1~.

  10. 10Move many files given by find

    find /tmp -maxdepth 1 -name "*.csv" -mtime +7 -exec mv -t /archive/ {} +

    -t makes it easy to use with find and xargs.

  11. 11Show each move

    mv -v *.jpg photos/

    Prints "renamed 'a.jpg' -> 'photos/a.jpg'".

انتبه

  • mv overwrites without asking (normal users). Use -i or -n.
  • Moved files keep their old SELinux label. Use mv -Z or run restorecon -Rv on the new place.
  • A typo in the target can rename instead of move: mv file /backp creates a file named /backp.

نصائح للحفظ

  • Same folder = rename. Other folder = move. -Z = new place, new SELinux label.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man mv