Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comprehensive List of dd Commands with Descriptions
#1
Comprehensive List of dd Commands with Descriptions

The `dd` command is a powerful and versatile utility used in Unix-like operating systems for low-level copying and conversion of files and data. Below is a comprehensive list of common `dd` commands with descriptions and examples.



1. Basic File Copying
Description: Copies a file from one location to another. The `if` parameter specifies the input file, and the `of` parameter specifies the output file.
Code:
dd if=/path/to/source/file of=/path/to/destination/file
Example: To copy `file1.txt` to `file2.txt`:
Code:
dd if=file1.txt of=file2.txt

2. Creating a Bootable USB Drive
Description: Writes an ISO image to a USB drive, making it bootable.
Code:
dd if=/path/to/image.iso of=/dev/sdX bs=4M status=progress
Example: To write `ubuntu.iso` to a USB drive:
Code:
dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress
Note: Replace `/dev/sdX` with the correct device identifier for your USB drive (e.g., `/dev/sdb`).

3. Creating a Disk Image
Description: Creates a disk image of a device or partition.
Code:
dd if=/dev/sdX of=/path/to/image.img bs=4M status=progress
Example: To create an image of the `/dev/sda` disk:
Code:
dd if=/dev/sda of=/backup/sda.img bs=4M status=progress

4. Restoring a Disk Image
Description: Restores a disk image to a device.
Code:
dd if=/path/to/image.img of=/dev/sdX bs=4M status=progress
Example: To restore an image to the `/dev/sda` disk:
Code:
dd if=/backup/sda.img of=/dev/sda bs=4M status=progress

5. Creating a Zero-Filled File
Description: Creates a file filled with zeros, often used to create a file of a specific size.
Code:
dd if=/dev/zero of=/path/to/file bs=1M count=100
Example: To create a 100MB file filled with zeros:
Code:
dd if=/dev/zero of=100mbfile.img bs=1M count=100

6. Writing Random Data to a File
Description: Writes random data to a file, which can be used for testing or security purposes.
Code:
dd if=/dev/urandom of=/path/to/file bs=1M count=100
Example: To create a 100MB file filled with random data:
Code:
dd if=/dev/urandom of=randomfile.img bs=1M count=100

7. Cloning a Disk
Description: Clones one disk to another. Useful for migrating data from one disk to another.
Code:
dd if=/dev/sdX of=/dev/sdY bs=64K conv=noerror,sync status=progress
Example: To clone `/dev/sda` to `/dev/sdb`:
Code:
dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync status=progress

8. Backing Up and Restoring the MBR (Master Boot Record)
Description: Backs up and restores the MBR, which includes the partition table and bootloader.
Code:
dd if=/dev/sdX of=/path/to/mbr_backup.img bs=512 count=1
Example: To back up the MBR of `/dev/sda`:
Code:
dd if=/dev/sda of=mbr_backup.img bs=512 count=1
To restore the MBR:
Code:
dd if=mbr_backup.img of=/dev/sda bs=512 count=1

9. View Progress of dd Command
Description: Displays the progress of a running `dd` operation. This is particularly useful for long operations like disk cloning or imaging.
Code:
dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync status=progress
Note: The `status=progress` option provides real-time updates on the amount of data copied.

10. Benchmarking Disk Performance
Description: Measures the read/write speed of a disk by copying data to and from `/dev/null` or `/dev/zero`.
Code:
dd if=/dev/zero of=/path/to/disk bs=1G count=1 oflag=direct
dd if=/path/to/disk of=/dev/null bs=1G count=1 iflag=direct
Example: To measure the write speed:
Code:
dd if=/dev/zero of=/tmp/testfile bs=1G count=1 oflag=direct

11. Converting File Format or Data
Description: Converts the format of data during copying. Common options include `conv=ucase` to convert text to uppercase and `conv=lcase` for lowercase.
Code:
dd if=/path/to/input.txt of=/path/to/output.txt conv=ucase
Example: To convert all text in a file to uppercase:
Code:
dd if=input.txt of=output.txt conv=ucase

12. Wiping a Disk
Description: Securely erases a disk by writing zeros or random data over it.
Code:
dd if=/dev/zero of=/dev/sdX bs=1M status=progress
Example: To wipe `/dev/sda` by writing zeros over it:
Code:
dd if=/dev/zero of=/dev/sda bs=1M status=progress
To wipe with random data:
Code:
dd if=/dev/urandom of=/dev/sda bs=1M status=progress

13. Splitting Output into Multiple Files
Description: Splits the output into multiple files, each of a specified size.
Code:
dd if=/path/to/input.file of=/path/to/output_prefix bs=1M count=100
Example: To split a large file into 100MB chunks:
Code:
dd if=largefile.iso of=splitfile bs=100M

14. Skipping Bytes During Copy
Description: Skips a specified number of blocks before copying data.
Code:
dd if=/path/to/input.file of=/path/to/output.file bs=512 skip=1
Example: To skip the first 512 bytes of a file:
Code:
dd if=input.file of=output.file bs=512 skip=1

15. Using gzip for Compression
Description: Compresses the output using gzip while copying data.
Code:
dd if=/dev/sdX | gzip > /path/to/image.gz
Example: To create a compressed disk image:
Code:
dd if=/dev/sda | gzip > sda_image.gz



Conclusion

The `dd` command is an incredibly versatile tool for copying and converting data, as well
Reply


Messages In This Thread
Comprehensive List of dd Commands with Descriptions - by Sneakyone - 09-03-2024, 01:51 AM

Forum Jump:


Users browsing this thread: 4 Guest(s)