> For the complete documentation index, see [llms.txt](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/dd.md).

# dd

## dd

The `dd` command in Unix and Unix-like operating systems is a powerful tool used for copying and converting files and data streams. It is commonly used for low-level operations such as disk cloning, backup, and data recovery, where precise control over input and output is required.

#### Basic Usage

The basic syntax for the `dd` command is:

```sh
dd [options]
```

#### Examples

**Copying a File**

To copy a file using `dd`:

```sh
dd if=inputfile of=outputfile
```

* **`if=inputfile`**: Specifies the input file (`inputfile`).
* **`of=outputfile`**: Specifies the output file (`outputfile`).

For example, to copy `file1.txt` to `file2.txt`, you would use:

```sh
dd if=file1.txt of=file2.txt
```

**Copying from a Block Device**

To copy the entire contents of one disk to another:

```sh
dd if=/dev/sda of=/dev/sdb
```

* **`if=/dev/sda`**: Input file (`/dev/sda` is typically the source disk).
* **`of=/dev/sdb`**: Output file (`/dev/sdb` is typically the destination disk).

This command clones `/dev/sda` to `/dev/sdb`, including partitions and file systems.

**Creating a Disk Image**

To create an image of a disk or partition:

```sh
dd if=/dev/sda of=disk.img bs=4M
```

* **`bs=4M`**: Specifies the block size (4 MB in this example) for improved performance.

**Monitoring Progress**

To monitor the progress of `dd` operations, you can use `pv` (pipe viewer) in conjunction with `dd`:

```sh
dd if=/dev/sda | pv | dd of=disk.img
```

#### Options

**Input and Output**

* **`if=inputfile`**: Specify the input file or device.
* **`of=outputfile`**: Specify the output file or device.
* **`bs=size`**: Specify the block size for reading and writing data.

**Count and Skip**

* **`count=n`**: Copy only `n` input blocks.
* **`skip=n`**: Skip `n` input blocks before starting the copy process.

**Progress Indicator**

* **`status=progress`**: Show progress information during operation (available in newer versions of `dd`).

#### Practical Use Cases

**Backup and Recovery**

`dd` is commonly used for creating disk images and backups, particularly in scenarios where traditional file-based backups may not suffice, such as system recovery.

**Forensics and Data Recovery**

For forensic analysis and data recovery, `dd` provides a low-level approach to copy and extract data from disks or partitions.

**Writing to Raw Devices**

`dd` can write directly to raw block devices (`/dev/sdX`), which is useful for tasks like flashing operating system images to USB drives or SD cards.

#### Caution

* **Data Loss**: Improper use of `dd`, such as selecting the wrong input or output device, can result in data loss. Always double-check the target device before executing a `dd` command.
* **Permissions**: `dd` operates at a low level and can overwrite data without warning. Ensure appropriate permissions and target device selection to avoid unintended consequences.

#### Summary

The `dd` command is a versatile tool for copying and converting data in Unix and Linux environments. It offers precise control over input and output operations, making it suitable for tasks like disk cloning, backup, and data recovery. Understanding its usage and options can help you leverage its capabilities effectively.

## help

```
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/dd.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
