---
title: "How do I create a copy of a directory in Unix/Linux?"  
description: "How do I create a copy of a directory in Unix/Linux?"  
author: "Utpal Vishwas"  
published: 2023-07-14  
updated: 2023-07-15  
canonical: https://www.mindstick.com/forum/159090/how-do-i-create-a-copy-of-a-directory-in-unix-linux  
category: "linux"  
tags: ["file", "linux"]  
reading_time: 2 minutes  

---

# How do I create a copy of a directory in Unix/Linux?

How do I create a [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) of a [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) in Unix/[Linux](https://www.mindstick.com/blog/11489/linux-os)?

## Replies

### Reply by Aryan Kumar

Sure, there are a few ways to create a copy of a directory in Unix/Linux. Here are two methods:

**Method 1: Using the** `cp` **command**

The `cp` command is a command-line utility that can be used to copy files and directories. To copy a directory using the `cp` command, you can use the following syntax:

```plaintext
cp -r SOURCE_DIRECTORY DESTINATION_DIRECTORY
```

For example, to copy the directory `/home/user/my_directory` to the directory `/home/user/my_backup`, you would run the following command:

```plaintext
cp -r /home/user/my_directory /home/user/my_backup
```

The `-r` option tells the `cp` command to recursively copy the directory, which means that it will also copy all of the subdirectories and files in the directory.

**Method 2: Using the** `rsync` **command**

The `rsync` command is a command-line utility that can be used to copy files and directories, and it is often considered to be a more powerful alternative to the `cp` command. To copy a directory using the `rsync` command, you can use the following syntax:

```plaintext
rsync -a SOURCE_DIRECTORY DESTINATION_DIRECTORY
```

The `-a` option tells the `rsync` command to copy all of the files and directories in the source directory, including the permissions, ownership, and timestamps.

Here is a table that summarizes the differences between the `cp` and `rsync` commands:

| Command | Option | Description |
| --- | --- | --- |
| `cp` | `-r` | Recursively copy the directory |
| `rsync` | `-a` | Copy all of the files and directories in the source directory, including the permissions, ownership, and timestamps |


---

Original Source: https://www.mindstick.com/forum/159090/how-do-i-create-a-copy-of-a-directory-in-unix-linux

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
