• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

dd Command Examples in Linux

by admin

The dd command copies and converts files to enable them to be transferred from one type of media to another. The dd command has various operands, or actions, to perform.

Operand Used To
if={file name} Specify the file from which data will be read.
of={file name} Specify the file to which data will be written.
bs={bytes} Specify the total block size to read and write, in bytes. Bytes can also be formatted in a more human-friendly way, such as 50M to specify 50 megabytes and 10G to specify 10 gigabytes.
count={blocks} Specify the number of blocks to be written to the output file from the input file.
status={level} Specify the level of information to print to standard error – none to suppress everything except error messages, noxfer to suppress total transfer statistics, progress to display transfer statistics periodically.

Syntax

The syntax of the dd command is:

# dd [options] [operands]

Using dd for backups

You can use dd to perform a full backup of a storage partition. The following example copies data from /dev/sda1 to /dev/sdb2:

# dd if=/dev/sda of=/dev/sdb

Using dd, you can also create an image of a drive and then clone a second drive with it:

# dd if=/dev/sda of=drive_image.iso 
# dd if=drive_image.iso of=/dev/sdb

dd Command Examples

1. To copy a file:

# dd if=old.txt of=old.txt 

2. To read and write specified bytes of a file at a time:

# dd bs=1024 if=old.txt of=old.txt 

3. To convert a file to a specified format:

# dd bs=1024 if=old.txt of=new.txt conv=ascii (from EBCDIC to ASCII)
# dd bs=1024 if=old.txt of=new.txt conv=ebcdic (from ASCII to EBCDIC)
# dd bs=1024 if=old.txt of=new.txt conv=ibm  (from ASCII to alternate EBCDIC)
# dd bs=1024 if=old.txt of=new.txt conv=block    (pad oldline-terminated records with spaces to cbs-size)
# dd bs=1024 if=old.txt of=new.txt conv=unblock (replace trailing spaces in cbs-size records with oldline)
# dd bs=1024 if=old.txt of=new.txt conv=lcase  (change upper case to lower case)
# dd bs=1024 if=old.txt of=new.txt conv=excl  (fail if the output old already exists)
# dd bs=1024 if=old.txt of=new.txt conv=notrunc   (do not truncate the output old)
# dd bs=1024 if=old.txt of=new.txt conv=ucase    (change lower case to upper case)
# dd bs=1024 if=old.txt of=new.txt conv=swab     (swap every pair of input bytes)
# dd bs=1024 if=old.txt of=new.txt conv=noerror  (continue after read errors)
# dd bs=1024 if=old.txt of=new.txt conv=sync    (pad  every  input  block  with  NULs to ibs-size)
# dd bs=1024 if=old.txt of=new.txt conv=fdatasync  (physically write output old data before finishing)
# dd bs=1024 if=old.txt of=new.txt conv=fsync  (likewise, but also write metadata) 

4. To copy only specified number of blocks:

# dd count=1024 if=old.txt of=new.txt 

5. To copy a file with specifying a flag:

# dd if=old.txt of=new.txt oflag=append
# dd if=old.txt iflag=directory of=new.txt oflag=directory
# dd if=old.txt iflag=noatime of=new.txt oflag=append 

6. To convert specified bytes at a time:

# dd cbs=1024 if=old.txt of=new.txt  

7. To read specified number of bytes at a time:

# dd ibs=1024 if=old.txt of=new.txt  

8. To write specified number of bytes at a time:

# dd obs=1024 if=old.txt of=new.txt

9. To skip specified number of blocks at start of o/p:

# dd seek=1024 if=old.txt of=new.txt 

10. To skip specified number of blocks at start of i/p:

# dd skip=1024 if=old.txt of=new.txt 

11. To suppress the transfer statistics:

# dd status=noxfer if=old.txt of=new.txt 

12. To erase the partition table for a device:

# dd if=/dev/zero of=/dev/sda4 bs=512 count=1 

Filed Under: Linux

Some more articles you might also be interested in …

  1. “Device /dev/mappper/mpath25 Not Found (or Ignored By Filtering)” – error while creating physical volume with pvcreate
  2. CentOS / RHEL 7 : Shutting Down, Suspending, or Rebooting Commands (systemctl)
  3. How to Use rpm2cpio Command in Linux
  4. How to log every shell command in Linux
  5. “Read-only locking type set. Write locks are prohibited. Can’t get lock for [volume group]” – error during lvextend
  6. The Squid Service in Failed State with Error: “Failed to make swap directory /var/spool/squid/00: (13) Permission denied”
  7. BTRFS: too many missing devices, writeable mount is not allowed
  8. How to Convert PuTTY’s private key (.ppk) to SSH key
  9. “Metadata File Does Not Match Checksum” Issue When Yum Installs or Updates Package
  10. Can’t start X11 applications after “su” or “su -” to another user

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright