How to mv in linux
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- The `mv` command can move files and directories to a new location.
- It is also used to rename files and directories.
- The basic syntax is `mv [options] source destination`.
- Moving a file into a directory with the same name will overwrite it without a prompt by default.
- The `-i` option can be used for interactive prompting before overwriting.
What is the `mv` command in Linux?
The `mv` command, short for 'move', is a fundamental utility in Linux and other Unix-like operating systems. Its primary purpose is to move files and directories from one location to another within the file system. However, it also serves a second crucial function: renaming files and directories. When you use `mv` to rename an item, you're essentially moving it within the same directory, but with a new name.
How to Move Files and Directories
The most common use of `mv` is to move one or more files or directories to a different directory. The basic syntax for moving is:
mv [options] source destination
Moving a Single File
To move a file named `report.txt` from your current directory to a directory called `documents`, you would use:
mv report.txt documents/
If the `documents` directory exists, `report.txt` will be moved into it. If `documents` does not exist, and you are moving a single item, `mv` will interpret `documents` as the new name for `report.txt` and rename it, which is usually not the intended behavior. Always ensure the destination directory exists before moving files into it.
Moving Multiple Files
You can move multiple files at once by listing them before the destination directory:
mv file1.txt file2.jpg image.png documents/
This command moves `file1.txt`, `file2.jpg`, and `image.png` into the `documents` directory.
Moving a Directory
Moving a directory works exactly the same way as moving a file:
mv my_folder/ backup/
This command moves the directory `my_folder` and all its contents into the `backup` directory.
How to Rename Files and Directories
Renaming is a special case of moving where the source and destination are in the same directory, but the destination specifies a new name.
Renaming a File
To rename a file named `old_name.txt` to `new_name.txt` in the current directory:
mv old_name.txt new_name.txt
Here, `old_name.txt` is the source, and `new_name.txt` is the destination, which is simply the new name for the file.
Renaming a Directory
Similarly, to rename a directory:
mv old_directory_name new_directory_name
Useful Options for `mv`
The `mv` command comes with several options that can modify its behavior:
- `-i` (interactive): Prompts for confirmation before overwriting an existing file. This is a very useful safety feature. Example:
mv -i important_file.txt backup/
- `-f` (force): Overwrites an existing file without prompting. Use with caution, as this can lead to accidental data loss. Example:
mv -f config.conf /etc/app/config.conf
- `-n` (no-clobber): Prevents overwriting an existing file. If the destination file already exists, the move operation for that specific file will be skipped. Example:
mv -n new_data.csv existing_data.csv
- `-u` (update): Moves the source file only if the destination file is older than the source file or if the destination file does not exist. Example:
mv -u latest_version.doc archive/
- `-v` (verbose): Explains what is being done. It lists each file as it's moved or renamed. Example:
mv -v *.txt text_files/
Important Considerations
Permissions: You need write permissions in the destination directory to move files into it. You also need write permissions on the parent directory of the source file/directory to remove it from its original location.
Overwriting: By default, if the destination file or directory already exists, `mv` will overwrite it without asking. This is a critical point to remember. Always double-check your destination, or use the `-i` option to prevent accidental data loss.
Symbolic Links: `mv` moves the actual file or directory, not the symbolic link itself, unless the link is the source and the destination is a new link name. If you move a file that a link points to, the link will continue to point to the original file's new location.
File Systems: On the same file system, `mv` is very fast because it only updates the directory entry (inode information) pointing to the data, essentially a rename operation. If you move files across different file systems, `mv` has to perform a copy operation followed by a delete operation, which takes longer and consumes more resources.
In summary, the `mv` command is an indispensable tool for managing files and directories in Linux, offering flexibility in both moving and renaming operations. Understanding its options and default behaviors, particularly regarding overwriting, is key to using it effectively and safely.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Mv (Unix) - WikipediaCC-BY-SA-4.0
- mv(1) - Linux man pagesCC-BY-SA-4.0
Missing an answer?
Suggest a question and we'll generate an answer for it.