How to mv multiple files 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 is used for both moving and renaming files and directories in Linux.
- Wildcards like `*`, `?`, and `[]` can be used with `mv` to select multiple files efficiently.
- The syntax is generally `mv [options] source1 source2 ... destination`.
- To move files into a directory, the destination must be an existing directory.
- If the destination is a file, `mv` will overwrite it (with potential confirmation depending on options and system configuration).
Overview
The Linux operating system provides a powerful and versatile command-line interface (CLI) that allows users to perform a wide range of tasks, from simple file operations to complex system administration. One of the most fundamental commands is `mv`, which stands for 'move'. While often used to rename files, its primary function is to move files and directories from one location to another within the filesystem. This capability is crucial for organizing your data, managing projects, and maintaining a clean and efficient file system. Moving multiple files at once is a common requirement, and Linux offers several straightforward ways to achieve this using the `mv` command, often in conjunction with shell features like wildcards.
Understanding the `mv` Command
The basic syntax for the `mv` command is:
mv [options] source destinationWhen moving a single file, the source is the file you want to move, and the destination is the target directory or the new name/path for the file.
When moving multiple files, the syntax extends to:
mv [options] source1 source2 source3 ... destinationIn this case, source1, source2, source3, etc., are the files or directories you wish to move, and the destination must be an existing directory. All the specified sources will be moved into that directory.
Moving Specific Multiple Files
The most direct way to move multiple, specifically named files is to list them all in the command. For instance, if you have `report.txt`, `notes.md`, and `summary.pdf` in your current directory and you want to move them to a directory named `documents` (which already exists), you would use:
mv report.txt notes.md summary.pdf ~/documents/Here, `~` represents your home directory, so `~/documents/` points to a `documents` folder within your home directory. If the `documents` directory does not exist, the command would likely fail or, depending on the exact `mv` implementation and context, might attempt to rename one of the source files to `documents` if only one source was provided, which is not the desired behavior for moving multiple files.
Leveraging Wildcards for Bulk Moves
Listing every file individually can be tedious, especially when dealing with many files that share a common pattern. This is where shell wildcards (also known as globbing patterns) become incredibly useful.
The Asterisk (`*`) Wildcard
The asterisk (`*`) is the most common wildcard. It matches any sequence of zero or more characters. For example:
- To move all files ending with the `.txt` extension to the `~/documents/` directory:
mv *.txt ~/documents/mv image_* ~/pictures/mv * ../Other Useful Wildcards
While `*` is the most frequent, other wildcards can refine your selection:
- Question Mark (`?`): Matches any single character. For example, `mv file?.txt` would move `file1.txt`, `fileA.txt`, but not `file10.txt`.
- Square Brackets (`[]`): Matches any one character within the brackets. For example, `mv file[123].txt` would move `file1.txt`, `file2.txt`, or `file3.txt`. You can also specify ranges, like `mv file[a-z].txt` to move files named `file` followed by a lowercase letter and then `.txt`.
Important Considerations and Options
Destination Must Be a Directory
When using `mv` to move multiple items, the final argument must be an existing directory. If you provide a name that doesn't exist as a directory, `mv` might behave unexpectedly, potentially trying to rename the last source item to that name if only one source was given, or throwing an error if multiple sources are provided and the destination isn't a directory.
Overwriting Files
If a file with the same name already exists in the destination directory, `mv` will typically overwrite it without asking. This can lead to data loss if you are not careful. You can use the following options to manage this behavior:
- `-i` (interactive): Prompts you before overwriting any existing file. This is a safer default for interactive use.
- `-n` (no-clobber): Prevents overwriting any existing file. If a file with the same name exists, the move for that specific file will be skipped.
- `-f` (force): Overrides the `-i` option and forces the move, even if it means overwriting. Use with caution.
Example using the interactive flag:
mv -i *.log /var/log/archive/Verbose Output (`-v`)
To see exactly which files are being moved and where, you can use the `-v` (verbose) option:
mv -v *.jpg ~/backup/images/This will print a line for each file indicating the source and destination, e.g., `'photo1.jpg' -> '/home/user/backup/images/photo1.jpg'`.
Moving Directories
The `mv` command works identically for moving directories. If you want to move a directory named `project_files` into another directory called `archives`, you would simply use:
mv project_files archives/If you list multiple directories, they will all be moved into the specified destination directory.
Common Scenarios and Examples
- Moving all `.log` files from `/var/log` to `/mnt/backup/logs`:
(Note: `sudo` might be required due to permissions in `/var/log`.)sudo mv /var/log/*.log /mnt/backup/logs/ - Moving all files starting with `temp_` into a newly created `~/temp_files` directory:
mkdir ~/temp_filesmv temp_* ~/temp_files/ - Moving specific files `a.txt`, `b.doc`, and `c.pdf` to the parent directory:
mv a.txt b.doc c.pdf ../
Conclusion
The `mv` command in Linux is a fundamental tool for file management. By understanding its basic syntax and mastering the use of wildcards, you can efficiently move multiple files and directories, keeping your filesystem organized and your workflow smooth. Always be mindful of potential overwrites and consider using options like `-i` or `-n` for safety, especially when working with critical data.
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 - move (rename) filesCC0-1.0
- GNU Coreutils: mv invocationGPL-3.0-or-later
- ExplainShell: mv command explanationfair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.