Skip to content
Log In Sign Up info@muvcloud.com

The mv Commands You Will Use Most

mv old-name.txt new-name.txt
mv report.pdf ~/backups/
mv *.log archive/
mv -i new.conf app.conf

The source comes first, the destination last. If the destination is an existing folder, the file moves into it and keeps its name. Otherwise the file gets the destination name. Folders move the same way and need no extra option.

Rename a File or Folder

mv index.html index.html.old
mv /var/www/staging /var/www/staging-2026

Within one filesystem, a rename is instant, whatever the size of the file or folder, because only the name changes.

Existing Files Are Overwritten Without a Question

If the destination file exists, mv replaces it silently and the old file is gone. Use one of these options when the destination might exist:

OptionWhat it does
-iAsks before overwriting.
-nNever overwrites; skips the file.
-bKeeps the old file with a ~ suffix.
-vPrints what was moved.

--backup=numbered keeps every replaced version as name.~1~, name.~2~, and so on.

Move Several Files into a Folder

mv a.txt b.txt c.txt ~/backups/
mv -t ~/backups/ a.txt b.txt c.txt

With more than one source, the last argument must be an existing folder. -t names the folder first, which is handy with xargs. When you move a single file, a trailing slash on the destination is a useful habit: if the folder does not exist, mv stops with an error instead of renaming your file to that name. For a folder as the source, the slash does not prevent the rename.

Wildcards

ls *.log
mv -n *.log archive/

The shell expands *.log before mv runs, so check the match with ls first. Two details matter: * does not match hidden files that start with a dot, and when nothing matches, bash passes the pattern unchanged and mv reports that it cannot stat *.log. For files spread over many folders, use find instead.

Rename Many Files at Once

mv renames one name at a time. To change the extension of every .txt file in a folder, use a loop; quoting keeps names with spaces intact:

for f in *.txt; do mv -n -- "$f" "${f%.txt}.md"; done

Run it with echo in front of mv first to print the commands without running them.

Moving Between Filesystems

When the source and destination are on different disks or partitions, for example from / to a mounted volume, mv copies the data and then deletes the original. That takes time on large folders. If the copy fails, mv removes the partial copy, but if the command is interrupted, part of the data may be in both places, so check both before you run it again. For large moves between disks, copy first with cp -a or rsync, check the copy, then delete the original. To move files to another server, see how to use SCP.

Common Errors

  • Permission denied: moving needs write permission on both the folder the file comes from and the folder it goes to. Use sudo for system folders.
  • Directory not empty: the destination already contains a non-empty folder with the same name. Merge the contents with cp -a or rsync instead.
  • Cannot move to a subdirectory of itself: the destination lies inside the source folder.
  • Not a directory: with several sources, the last argument is a file or does not exist.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations