How to Copy a Directory Linux

You can use the command with the option to copy a directory in Linux. The -r option stands for “recursive,” meaning it will copy the directory and all its contents, including subdirectories.

Here are the steps to copy a directory in Linux:

Use the cp -r Command

Step 1 – Open your terminal.

Open your terminal, either connect to the server via SSH, via the console, or bash shell

Step 2 – Use the cp -r command to copy a directory

Type the following command and press Enter:bash

ShellScript
cp -r /path/to/source/directory /path/to/destination/directory

Replace /path/to/source/directory with the path to the directory you want to copy and /path/to/destination/directory with the path to the location where you want to copy the directory.

Press Enter.

The cp command will copy the directory and all of its contents to the destination directory. If the destination directory does not exist, it will be created.

Use Rsync

One alternative method is to use the rsync command, which is a powerful tool for syncing and transferring files between directories or systems.

Here are the steps to copy a directory using rsync:

Step 1 – Open your terminal.

Open your terminal, either connect to the server via SSH, via the console, or bash shell

Step 2 – Use the rsync command to copy a directory

Type the following command and press Enter:bash

ShellScript
rsync -av /path/to/source/directory/ /path/to/destination/directory/

Replace /path/to/source/directory/ with the path to the directory you want to copy and /path/to/destination/directory/ with the path to the location where you want to copy the directory.Note the use of the trailing slashes after the directory paths. This tells rsync Copy the source directory’s contents to the destination directory, rather than creating a new directory within the destination directory.

Press Enter.

The rsync command will copy the directory and all of its contents to the destination directory. Unlike the cp command, rsync also provides options for incremental copying, partial transfers, and resuming interrupted transfers, which can be useful for large or complex directory structures.

Want to learn more Linux facts? Check out the rest of our Tech Quicky content!!
Elsewhere On TurboGeek:  How to Install Jira from Atlassian on Ubuntu

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป