HOWTO · Linux

How to Move Multiple Files in Linux Bash

Learn how to move multiple files in Linux Bash with `mv`, using explicit filenames and wildcard patterns to select files by name or extension.

On this page

To move several files into one Linux directory, put the source paths first and the destination directory last. You can name each source or let Bash expand a wildcard pattern before it starts mv. The examples below use a small set of files so you can see how each selection method behaves.

Prepare the example files and destination

This consolidated example creates six files in Folder1, creates Folder2, and demonstrates all three moves in sequence. Run it from Bash; its temporary working directory is removed when the script exits. The move commands in the sections below are alternatives, not additional steps on the files left by this script. To try any one of them, open a fresh Bash session and recreate the starting files with work=$(mktemp -d); cd "$work"; mkdir Folder1; cd Folder1; touch file1.txt file1.pdf file2.txt file2.pdf file3.txt file3.pdf; mkdir Folder2. Then run only the section’s move command.

Run this example:

set -eu
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cd "$work"
mkdir Folder1
cd Folder1
for name in file1.txt file1.pdf file2.txt file2.pdf file3.txt file3.pdf; do
  : > "$name"
done
mkdir Folder2
mv file1.txt Folder2/
mv file2.* Folder2/
mv *.pdf Folder2/
printf 'Files now in Folder2:\n'
printf '%s\n' Folder2/*
Files now in Folder2:
Folder2/file1.pdf
Folder2/file1.txt
Folder2/file2.pdf
Folder2/file2.txt
Folder2/file3.pdf

Folder2 is created before the moves. The final listing contains five files: file3.txt stays in Folder1 because none of the three source selections matched it.

Move specific files with mv

When you know the exact names, list each one before the destination: mv file1.txt file2.txt file3.txt Folder2/. Bash passes these names as separate arguments, and mv moves each source into the last argument. A trailing slash on an existing directory is optional, so Folder2 also works.

Use explicit names when you want a carefully chosen set, especially if files with other names or extensions must remain where they are. For a long list, check spelling and capitalization; Linux paths are case-sensitive. If a source path is wrong, mv reports an error rather than moving that source.

Use * to match similar filenames

An asterisk matches any sequence of characters in a filename. For example, mv file2.* Folder2/ selects files whose names begin with file2. and have any suffix, such as file2.txt and file2.pdf. This is useful when a related group has a shared basename but different extensions.

The pattern is expanded against entries in the current directory. It does not search nested directories, and it can also match a directory whose name fits the pattern. Check the matches first if the directory contains similarly named folders or files you do not intend to move.

Use * to match a file extension

To select files by extension, put the extension after the asterisk: mv *.pdf Folder2/ moves matching PDF files from the current directory. The pattern covers any basename ending in .pdf; it does not include files in subdirectories or uppercase .PDF names.

Quote marks prevent Bash from expanding a wildcard. Thus mv '*.pdf' Folder2/ passes the literal pattern as one source name, which is usually not what you want for a group of files. Leave the pattern unquoted when you intend Bash to match filenames.

Check matches and destination behavior

Before moving a group, inspect the expansion with printf '%s\n' *.pdf. This prints one matching path per line without changing files. In Bash’s default configuration, when no path matches, the pattern remains literal; a later mv then reports that it cannot find that source. Shell options such as nullglob change this behavior, so do not assume every unmatched pattern disappears.

When mv receives multiple sources, the final argument must name an existing directory. Create it first with mkdir -p Folder2 if appropriate. If that final path is not a directory, mv cannot place several sources there. Also review any existing files in the destination: a move can replace a same-named destination file, subject to the command’s options and system behavior. Use the match check and destination listing to confirm the selected sources and avoid surprises.