Linux allows you to easily work with files & directories. Sometimes you may need to merge folders & directories in Linux. In this article, we will learn how to merge folders & directories in Linux.
How to Merge Folders & Directories in Linux
Here are the steps to merge folders & directories in Linux. cp is one of the simplest commands to help you merge folders & directories in Linux.
Here is the syntax to copy multiple folders into a single one.
cp -rv /path/to/copy1 /path/to/copy2 /path/to/copy3 /dest/dir
For example, if you want to copy contents of folders /home/ubuntu/data1, /home/ubuntu/data2, /home/ubuntu/data3 into /home/ubuntu/projects then you can use the following command.
cp -rv /home/ubuntu/data1 /home/ubuntu/data2 /home/ubuntu/data3 /home/ubuntu/projects
Basically, you need to list all the folders that you want to combine one after the other in space-separated manner and mention the destination folder at the end of the command.
You can customize these commands as per your requirement.
Also read:
How to Split Folder into Subfolders in Linux
How to Split Large File into Smaller Files in Linux
How to Sort Files into Folders in Linux
How to Add Newline After Pattern in Vim
How to Convert CRLF to LF in Linux
Related posts:
How to Password Protect PDF in Linux
How to Check if Directory Exists in Shell Script
How to Show Asterisk for Password in Ubuntu
pgAdmin Connect Via SSH Tunnel
How to Use Key-Value Dictionary in Shell Script
Shell Script to Read Data from Text File using For Loop
How to Append Text At End of Each Line in Linux
How to Format USB Drives in Linux

Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.