Want to copy a folder to another location using the terminal but don't know how? The cp command on Linux is what you need. In this post, you'll learn how to quickly copy directories in Linux in an efficient way.

How to Copy Directories in Linux With cp

Linux comes with an official package that allows you to copy directories within your system. The cp command is a powerful utility that is used to create copies of files and folders easily.

The basic syntax of the cp command is:

        cp [options] <sourcefolder> <destinationfolder>
    

You can also copy and paste files using cp. The syntax to copy files is quite similar to the aforementioned command.

Copy a Single Folder in Linux

To simply copy and paste a folder to another location on your system, use the following syntax:

        cp <source> <destination>
    

To copy a folder named /random to the /home directory:

        cp /random /home
    

If the source folder includes multiple sub-folders, then you need to use the -R flag with the cp command. The -R stands for recursive, which means that the executed command will be valid for the sub-directories as well.

To copy the /random folder recursively to /home directory:

        cp -R /random /home
    

Copy Multiple Directories

You can copy multiple directories to a single location with the cp command as well. All you need to do is pass the folder names separated with a Space character in the default cp command.

        cp <folder1> <folder2> <folder3> <folder4> <destination>
    

For example, to copy the folders /random, /personal, and /content to the /home directory:

        cp /random /personal /content /home
    

You can also use the -R flag while copying multiple folders.

        cp -R /random /personal /content /home
    

Managing Folders on Linux With cp

For those who are just getting started with Linux, cp is one of the most important commands that you'll need. The mv command is also essential if you want to move files and folders on a Linux system instead of copying them.

For beginners, learning some basic Linux commands will not only improve the initial experience with the operating system but will also ease out the process of getting comfortable with Linux for them.