How to Move Multiple Files in Linux Bash

Yahya Irmak Feb 02, 2024
How to Move Multiple Files in Linux Bash

In this article, we will introduce how to move multiple files into the same directory in Linux. We will explain different methods such as typing multiple filenames, using a wildcard (*) for similar filenames and/or the same file extensions.

The sample files and directories we will use throughout the article are below.

Files and directory structure

You can use the following commands to create this structure.

mkdir Folder1
cd Folder1
touch file1.txt
touch file2.txt
touch file3.txt
touch file1.pdf
touch file2.pdf
touch file3.pdf
mkdir Folder2

Move Multiple Files With the mv Command in Linux

After the mv command, type the filenames you want to move and then the directory name. The use of a slash (/) after the directory name is optional.

mv file1.txt file1.pdf file2.txt Folder2/

Move with filenames

Use Wildcard (*) for Similar Filenames

Asterisk (*) is called wildcard, and it gives every file that starts with the specified name as a parameter to the mv command.

Let’s say we want to move all files with the name file1, even if the extension is different. We use a wildcard instead of specifying the extension at the end of the filename.

mv file1.* Folder2/

Wildcard for similar filenames

Use Wildcard (*) for Same Extension

This time, we want to move all files with the same extension, even if their names are different. We use a wildcard instead of the filename then write the extension we want at the end.

mv *.pdf Folder2/

Wildcard for same extension

Author: Yahya Irmak
Yahya Irmak avatar Yahya Irmak avatar

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

LinkedIn

Related Article - Linux File