Use the Linux mv command to move a file: mv source destination. For example, mv report.txt Documents/ moves report.txt into the Documents directory; if the destination is a new filename, mv renames the file instead.
Basic Syntax and Examples
The general form is mv [options] source destination. Paths can be relative to your current directory or absolute, such as /home/sam/Documents/report.txt. A relative path like Documents/ is interpreted from the directory shown by pwd.
- Move one file into an existing directory:
mv notes.txt Documents/. - Move and rename a file in one step:
mv notes.txt Documents/meeting-notes.txt. - Move a file to a specific path, giving it a new name:
mv photo.jpg /tmp/holiday.jpg. - Move a file up one directory:
mv draft.txt ../.
When the destination names an existing directory, mv places the source inside it and keeps the original filename unless you specify another name. When the destination is not an existing directory, it is treated as the new path or filename. This distinction explains why a misspelled directory name can result in an unexpected rename.
Move Multiple Files
You can provide several source files, but the final argument must be an existing destination directory. For example, mv jan.csv feb.csv archive/ moves both files into archive. The command fails if that directory does not exist or if the final argument is not a directory when there are multiple sources.
Shell wildcards can select groups of files. For example, mv *.log logs/ moves files in the current directory whose names end in .log into logs. The shell expands *.log before running mv; it is not a special feature of mv. Check which files match first with ls *.log if the selection matters. Depending on your shell and settings, a pattern with no matches may be passed literally or produce an error.
What Happens When You Move a File
Moving a file within the same filesystem usually changes its directory entry rather than copying all its contents. As a result, it is typically quick, even for a large file. Moving a file across filesystems—such as from a disk to a mounted USB drive—generally requires copying the data to the destination and removing the original after the copy succeeds. That can take time and requires enough free space at the destination.
The move does not normally change the file’s contents, but permissions and other metadata may be affected by filesystem boundaries, mount options, or system policies. A move can also fail because you lack permission to modify the source directory or destination directory. File ownership and access behavior are governed by the operating system and destination filesystem, so do not assume every attribute will remain identical when moving between different storage types.
Overwrite Protection and Useful Options
If a destination file already exists, ordinary mv may replace it. That makes it important to check the destination before moving files you cannot easily recreate. Common options let you choose how to handle an existing destination:
mv -i source destinationasks before overwriting an existing file. This is a useful choice for interactive use.mv -n source destinationavoids overwriting an existing destination. Exact behavior can vary between implementations, so consult the local manual page for scripts that depend on it.mv -f source destinationforces replacement without the usual interactive protection. Use it only when replacement is intended.mv -v source destinationprints each move as it happens, making the result easier to review.
Options and details can differ across systems. Linux distributions commonly provide GNU Coreutils, but a system may use another implementation. Run man mv or mv --help to see what the installed command supports. Avoid relying on an interactive prompt as a backup in automated scripts: scripts should check conditions and handle errors explicitly.
Common Problems and Safer Habits
“No such file or directory” usually means a source path is wrong, a destination directory is missing, or the command is being run from an unexpected working directory. Confirm your location with pwd and inspect relevant paths with ls. Quote paths containing spaces, such as mv "quarterly report.txt" Reports/; without quotes, the shell treats the words as separate arguments.
“Permission denied” commonly means your account cannot access or modify one of the relevant directories. Check permissions before considering elevated privileges. Avoid using sudo reflexively: it can move a file into a location your normal account cannot manage, or replace a system file. Use it only when you understand why administrative access is required.
- For important files, confirm both source and destination paths before pressing Enter.
- Use
-iwhen you want a prompt before replacement, or move to a temporary directory first when uncertain. - For a complicated wildcard, preview the matching filenames before running the move.
- Afterward, check the destination with
lsor a file manager. A successful command is usually silent unless you use-v.
Do not confuse mv with a guaranteed backup operation. If a file is overwritten, recovery may not be straightforward, and behavior depends on the filesystem and available backups. Make a separate copy of valuable data before a risky operation.
How mv Compares with cp and Rename Tools
mv moves or renames; cp creates a copy and leaves the original in place. Use cp source destination when you need both copies, and mv when the file should end up at the new location rather than remain at the old one. For directories, mv can move a directory and its contents, subject to permissions and filesystem rules; it does not require a recursive option for an ordinary directory move.
For renaming many files according to a pattern, a dedicated tool such as rename may be more suitable, but its syntax and availability vary among Linux distributions. For one file, mv old-name new-name is the straightforward choice.
Frequently Asked Questions
How do I move a file to another folder in Linux?
Run mv filename folder/, replacing filename and folder/ with the actual file and destination. Use a full path if the destination is elsewhere.
Does mv rename a file?
Yes. When the destination is a new filename or path rather than an existing directory, mv renames the file or moves it under that new name.
How do I move a file without overwriting another file?
Use mv -i source destination to be prompted before replacement, or mv -n source destination where supported to avoid replacing an existing destination. Check man mv for your system’s behavior.
How do I move hidden files?
Specify a hidden filename explicitly, for example mv .config backup/. In common shells, * does not match names beginning with a dot by default, so mv * destination/ may leave hidden files behind.
How do I move a directory in Linux?
Use the same basic form: mv directory destination/. The destination must be accessible, and moving across filesystems can involve copying the directory’s contents before removing the source.