HOME ABOUT Search this website
TRENDING FREE EBOOKS
LINUX HOWTO
LINUX DISTROS
LINUXLINUX
COMMANDS
COMMANDS
Learn Linux DD Command - 15 Examples With
LINUX TOOLS
AUTOMATION
All Options
SHELL SCRIPTS
June 24, 2011 | By Leena More
DEVOPS ! " # $
WEB SERVERS
UBUNTU HOWTO
The Linux command ‘dd’ is one of the most powerful utility which can be used in a variety of
ways. This tool is mainly used for copying and converting data, hence it stands for ‘data
duplicator’.
This tool can be used for:
• Backing up and restoring an entire hard drive or a partition.
• Copy regions of raw device files like backing up MBR (master boot record).
• Converting data formats like ASCII to EBCDIC.
• Converting lowercase to uppercase and vice versa.
• Creating files with fixed size.
Only superuser can execute this command. You should be very careful while using this
command as improper usage may cause huge data loss. So, some people consider this tool as
‘data destroyer’.
Syntax of ‘dd’ command.
dd if=<source file name> of=<target file name> [Options]
We will learn the various ‘options’ while going through the examples.
1. Backing up and restoring an entire hard drive or a partition.
a. Backup entire hard drive to another drive.
dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerror,sync
Here, ‘if’ stands for input file , ‘of’ stands for output file and ‘bs’ stands for the block size
(number of bytes to be read/write at a time). The conversion parameter ‘noerror’ allows the tool
to continue to copy the data even though it encounter any errors. The sync option allows to use
synchronized I/O.
The above command will copy all the data from the disk /dev/sda to /dev/sdb. ‘dd’ doesn’t know
anything about the filesystem or partitions; it will just copy everything from /dev/sda to /dev/sdb.
So, this will clone the disk with the same data on same partition.
b. Creating a disk image.
dd if=/dev/sda of=/tmp/[Link]
Backing up a disk to an image will be faster than copying the exact data. Also, disk image make
the restoration much more easier.
c. Creating a compressed disk image.
dd if=/dev/sda | gzip >/tmp/[Link]
d. Restoring hard disk image.
dd if=/tmp/[Link] of=/dev/sda
e. Restoring compressed image.
gzip –dc /tmp/[Link] | dd of=/dev/sda
f. Clone one partition to another.
dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror,sync
This will synchronize the partition /dev/sda1 to /dev/sdb1. You must verify that the size of
/dev/sdb1 should be larger than /dev/sda1
2. Backing up and restoring MBR.
Master Boot record is the boot sector which houses the GRUB boot loader. If MBR
gets corrupted, we will not be able to boot into Linux. MBR -512 byte data- is located at the first
sector of the hard disk. It consists of 446 byte bootstrap, 64 byte partition table and 2 bytes
signature.
a. Backing up MBR.
dd if=/dev/sda of=/tmp/[Link] bs=512 count=1
The option “count” refers to the number of input blocks to be copied.
b. Backing up the boot data of MBR excluding the partition table.
dd if=/dev/sda of=/tmp/[Link] bs=446 count=1
c. Restoring MBR from MBR image.
dd if=/tmp/[Link] of=/dev/sda
d. Display master boot record.
dd if=/dev/hda of=[Link] bs=512 count=1
od -xa [Link]
3. Converting data formats.
a. Convert the data format of a file from ASCII to EBCDIC.
dd if=[Link] of=[Link] conv=ebcdic
b. Convert the data format of a file from EBCDIC to ASCII
dd if=[Link] of=[Link] conv=ascii
4. Converting case of a file.
a. Converting a file to uppercase.
dd if=file1 of=file2 conv=ucase
b. Converting a file to lowercase.
dd if=file1 of=file2 conv=lcase
5. Creating or modifying data files.
a. Create a fixed size, say 10MB file.
dd if=/dev/zero of=file1 bs=10485760 count=1
The block size is calculated as 10MB=10*1024*1024.
b. Modify the first 512 bytes of a file with null data.
dd if=/dev/zero of=file1 bs=512 count=1 conv=notrunc
The option ‘notrunc’ refers to do not truncate the file, only replace the first 512 bytes, if it exists.
Otherwise, you will get a 512 byte file.
Conclusion.
These are the some examples of ‘dd’ command usage. This ‘data duplicator’ command can be
used in a lot more ways in your daily administration tasks.
You might also like
Can dd Command Used To Wipe Data? Examples
7 Examples To Delete/Erase Contents Of File In Linux But Not File
Linux System Performance Monitoring Using Sar Command
How To Backup LVM Configuration On Linux (vgcfgbackup & vgcfgrestore)
rsync Command to Exclude a List of Files and Directories in Linux
Fdisk Commands – Manage Partitions in Linux
Linux du Command All Options To Study
Linux Uptime Command – Find How Long Your System Been Running
How to Setup smokePing for Latency Monitoring on Ubuntu 15.04
DD Utility – Easily Backup and Restore Disk Image Files In Ubuntu
Filed Under : LINUX COMMANDS
Tagged With : dd Linux
Free Linux Ebook to Download
PREVIOUS ARTICLE
About Unix Scopeux Daemon
NEXT ARTICLE
Install/Configure/Stages Of Linux GNU Grub Bootloader
Comments (4)
Trackback URL | Comments RSS Feed
1. Pawan says:
August 26, 2014 at 5:25 pm
Thanks very nice explanation of DD command. I love making files for SWAP with this
command.
Reply
2. HyunWoo Jo says:
March 16, 2015 at 4:23 pm
Thank you for good example.
Reply
3. DANIEL NJORA KAGUONGO says:
July 16, 2016 at 1:28 am
I have gained a lot.
Reply
4. Roderick says:
December 23, 2016 at 12:08 pm
Sorry if I ask a dumb question, but will the below command
dd if=/tmp/[Link] of=/dev/sda
not destroy the /dev/sda, leaving only the MBR?
You see, if I have, say, a file [Link] with '123456789' in its contents and I run
dd if=/dev/zero of=[Link] bs=1 count=1
it will put 1 byte into this file, wiping out everything else.
To only replace the first byte, AFAIK, I have to use conv=notrunc parameter, i.e.
dd if=/tmp/[Link] of=/dev/sda conv=notrunc
Then only the first byte is change and everything else stays intact.
Reply
Leave a Reply
Name( required )
Email ( required; will not be published )
Website
Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.
What is linoxide based on ? Windows or Linux ? Type your answer into the box
Submit Comment
Popular Posts
1 Linux Commands Cheat Sheet in Black & White
2 Shell Script to Check Linux System Health
3 Colourful ! systemd vs sysVinit Linux Cheatsheet
4 Intro to Configure IPsec VPN (Gateway-to-Gateway ) using Strongswan
5 How to Install CentOS 7 Step by Step with Screenshots
6 How to Install and Setup Asterisk 13 (PBX) on Centos 7.x
7 Linux ntopng - Network Monitoring Tool Installation (Screenshots)
8 How to Install / Setup rtorrent and rutorrent in CentOS / Ubuntu
9 How to Install GNOME 3.16 On Ubuntu, Mint and Arch Linux
10 How to Setup ClipBucket to Start Video Sharing Website in Linux
11 How to Install Roundcube Webmail on Ubuntu16.04
12 Install Vivaldi in Linux - Awesome Multi Platform Browser
13 70 Shell Scripting Interview Questions & Answers
14 How To Use Ip Command In Linux with Examples
15 25 Linux Interview Questions and Answers (Basic and Scenarios)
Linux Trends
[Link]/+Linoxide
Theo dõi +1
+ 4.892
Your Matched Resources
Linux
Commands
Cheat Sheet...
15 Linux cp
Command
Examples -...
How to install
DD Utility and...
LINUX
COMMANDS
Linux 'make'
Command
Explained...
Can dd
Can dd
Command
Used To Wipe...
rsync
Command to
Exclude a List...
How Linux
Administrator
Monitor High...
Understanding
Each Entry Of
Linux Fstab (...
How To Use
Lsblk To List
Block Device...
How To Fix /
Repair Bad
Blocks In Linux
Subscribe To Free Newsletter
Enter email address to subscribe and receive notifications of new posts by
email
Join 10400+ Other Subscribers
Enter Your Email * SUBSCRIBE
100% privacy - We will never spam you
Free tool for
ProdMgmt
Powerful project management
for product managers
LINUX COMMANDS LINUX TOOLS SUBSCRIBE TO FREE
NEWSLETTER
All You Need to Know About Linux
How
Killto Setup Network Monitoring with
Command From Scratch OpenNMS on Ubuntu 16.04 Enter your email
address to subscribe to
20 SEP, 2016 1 FEB, 2017 this blog and receive
notifications of new
How to Install perf Tool on CentOS
Howand
toUbuntu posts by email
Make Call using Opensource Voip
Linphone on Ubuntu
19 SEP, 2016
Join 10400+ Other
31 JAN, 2017
Unix Z Commands – Zcat, Zless, Zgrep, Zegrep Subscribers
and Zdiff Examples How to Setup Teampass Password Manager on
Enter Your Email *
Ubuntu 16.04
7 SEP, 2016
SUBSCRIBE
30 JAN, 2017
How to Track Progress % of Commands
(cp,dd,tar) in CentOS 6 / Fedora How to Setup Foreman to Manage Puppet
5 SEP, 2016 Nodes on Ubuntu 16.04 100% privacy - We will never
26 JAN, 2017
spam you
Run Command Parallel on Multiple Hosts
using PDSH Tool TAGS
How To Synchronize Directories using
30 AUG, 2016 Syncthing on Ubuntu 16.04
Apache Backup Clustering
24 JAN, 2017
Powerful SSH Command Options with Command Container Docker
Examples on Linux Filesystem Firewall Freebsd
26 JUL, 2016 Monitoring Network Nginx
Ssh Storage Ubuntu 16
watch - Repeat Linux / Unix Commands
Regular Intervals
© 2017 LinOxide. All rights
4reserved.
JUN, 2015
Contact Us | Privacy | Terms of Service
A Peep into Process Management Commands
in Linux
25 MAR, 2015
How to Manage Network using nmcli Tool in
RedHat / CentOS 7.x
14 JAN, 2015
Interface (NICs) Bonding in Linux using nmcli
5 JAN, 2015
How to Sync Time Properly with NTP Server in
CentOS 7.x
28 NOV, 2014
A Great Tool To Show Linux Command
Progress Like % , ETA
24 NOV, 2014
Linux blkid Command to Find Block Devices
Details
21 NOV, 2014
Important 10 Linux ps command Practical
Examples
19 NOV, 2014
timedatectl - Control Linux System Time and
Date in Systemd
5 NOV, 2014
rsync Command to Exclude a List of Files and
Directories in Linux
27 OCT, 2014
pidstat - Monitor and Find Statistics for Linux
Procesess
6 OCT, 2014
Linux ss Tool to Identify Sockets / Network
Connections with Examples
1 OCT, 2014
Colourful ! systemd vs sysVinit Linux
Cheatsheet
5 SEP, 2014
Awesome ! systemd Commands to Manage
Linux System
29 AUG, 2014
8 Options to Trace/Debug Programs using
Linux strace Command
18 AUG, 2014
How to Change Hostname in RHEL / CentOS
7.0
16 AUG, 2014
Linux Systemd - Start/Stop/Restart Services in
RHEL / CentOS 7
15 AUG, 2014
A Pocket Guide for Linux ssh Command with
Examples
13 AUG, 2014
How to Merge Directory Trees in Linux using cp
Command
23 JUL, 2014
Linux slabtop command - Display Kernel Slab
Cache Information
11 JUL, 2014
Linux chpasswd Command - Change
Passwords in Bulk Mode
7 JUL, 2014
Advanced Directory Navigations Tips and
Tricks in Linux
23 JUN, 2014
How to use Linux lsblk Command to List Block
Device Information
16 JUN, 2014
Linux script command - A recorder inside your
Terminal
30 MAY, 2014
How To Use Ip Command In Linux with
Examples
2 MAY, 2014
Why htop Command Compete Linux top
Command
28 APR, 2014
Linux findmnt Command To Find Mounted
Filesystems
28 MAR, 2014
Linux Commands Cheat Sheet in Black & White
21 MAR, 2014
What Options you use for Linux killall
Command ? I have 5 Options
14 MAR, 2014
10 ssh options for a Secure shell for Safe Data
Communication
2 MAR, 2014
Some powerful options of Linux Dig command
to Query DNS
26 FEB, 2014
Power of Linux wget Command to Downloand
Files from Internet
24 FEB, 2014
Best all Options for DNS lookup using Linux
host command
19 FEB, 2014
Linux head Command Options with Examples -
Display First Part of Files
14 FEB, 2014
Linux more Command - Display Long Text File
Per page at a Time
10 FEB, 2014
Linux touch command - Why do we need to
change Timestamp?
5 FEB, 2014
Moving or Rename File / Directory in Linux - 10
Practical mv Command Examples
3 FEB, 2014
Linux rm Command Examples - Should be
Aware and Cautious
27 JAN, 2014
Create Directory - subdirectory, other than that
What mkdir command do in Linux
23 JAN, 2014
15 Linux cp Command Examples - Create a
Copy of Files and Directories
14 JAN, 2014
Linux pwd command - Know Your Current
Working Directory
10 JAN, 2014
20 Linux ls Command Examples to Display the
Entries of Directory
9 JAN, 2014
userdel Command - Delete User Account from
Linux system
1 JAN, 2014
Linux free Command - Display Free and used
Memory in the System
28 DEC, 2013
Understanding Linux cd Command with
Examples
26 DEC, 2013
Linux who command - Displays who is on the
system
22 DEC, 2013
Linux id Command - Print user ID and group ID
information
21 DEC, 2013
Linux iostat Command to Report CPU Statistics
and I/O Statistics
20 DEC, 2013
Linux vmstat Command - Tool to Report Virtual
Memory Statistics
17 DEC, 2013
Linux lsusb Command to Print information
about USB on System
14 DEC, 2013
Linux mpstat Command - Reports Processors
Related Statistics
13 DEC, 2013
Linux whoami command - Knowing Who is
Logged In
12 DEC, 2013
Linux dmesg Command to Print or Control the
Kernel Ring Buffer
10 DEC, 2013
How to use Linux Netcat Command as Port
Scanner
10 DEC, 2013
Linux w Command to See Who is Logged In
And What Doing
10 DEC, 2013
Linux cal and ncal Commands to Display
Calender
8 DEC, 2013
Linux date command - Display and Set System
Date and Time
7 DEC, 2013
Using Password Aging to Secure your Linux
Access
6 DEC, 2013
Built in Audit Trail Tool - Last Command in
Linux
3 DEC, 2013
How To Display And Set Hostname in Linux
1 DEC, 2013
Unbelievable ! 30 Linux TOP Command
Examples With Screenshots
28 NOV, 2013
Linux Uptime Command - Find How Long Your
System Been Running
24 NOV, 2013
20 Linux Cat Command Examples For File
Management
23 NOV, 2013
Linux diff Command Explained With Examples
20 NOV, 2013
9 Linux Uname Command Examples To Get
Operating System Details
17 NOV, 2013
Package Management Using YUM In Red Hat
Linux
6 NOV, 2013
Options in Linux RPM Command to Query
Packages
30 SEP, 2013
Linux Pmap Command - Find How Much
Memory Process Use
11 SEP, 2013
Linux Change File / Directory Ownership -
Chown Command
5 SEP, 2013
Linux Change File Permission - Chmod
Command
2 SEP, 2013
Power Of Linux Sort Command
26 AUG, 2013
Power Of Linux sed Command
19 AUG, 2013
Fg/Bg Command - Linux Manage Process
Foreground / Background
12 AUG, 2013
Linux wc Command - File Count Options
5 AUG, 2013
Linux Groupadd Command - Adding New
Groups
29 JUL, 2013
Managing Linux Services at Startup With
Chkconfig Command
22 JUL, 2013
Linux User Add Command And Its All Options
8 JUL, 2013
Linux Tail Command Options With Examples
1 JUL, 2013
Linux Process And Directory Structure Tree
Commands
24 JUN, 2013
Linux du Command All Options To Study
20 JUN, 2013
Linux - Finger Command To Find User Details
29 MAY, 2013
Linux df command - Disk Space Usage For
Filesystems
9 MAY, 2013
Chattr Command or Change Attributes of File
5 MAY, 2013
Linux ifconfig : How To Set Ip Address /
Configure Interface
17 APR, 2013
Linux Umask : Permission Set When New File /
Folder Created
15 APR, 2013
5 Ways To Find Linux Kernel Version
11 APR, 2013
How To Tar Linux Files Into .tgz Compressed
Extension
3 APR, 2013
Linux Word Count wc Command With Example
18 MAR, 2013
Manage Linux Group Using gpasswd
Command
14 MAR, 2013
Detailed Understanding Of Linux Inodes With
Example
1 FEB, 2013
Linux - Limit Process At User Level
30 JAN, 2013
Linux - List / Show Users Thats Belongs
Corresponding Groups
28 JAN, 2013
Fdisk Commands - Manage Partitions in Linux
26 JAN, 2013
Commands To Understand Page Faults Stats In
Linux
10 JAN, 2013
Learn Linux Nmap Command With Examples
29 DEC, 2012
Linux - How To Safely Remove External Drives
11 DEC, 2012
Linux - Memory Analysis With Free and Pmap
Command
8 DEC, 2012
Examples - Linux Shutdown Commands
5 DEC, 2012
Example : Linux Command To Add User To A
Group
30 NOV, 2012
Create User In Linux From Command Line And
Its Options
28 NOV, 2012
Linux Command To Change Password For Root
/ User / Group
25 NOV, 2012
Example How To Use Linux nohup Command
23 NOV, 2012
Easy Linux Command To Change Runlevels
21 NOV, 2012
HowTo : Reboot Linux Server Command Line
And Remotely
10 NOV, 2012
Rsync Over Ssh On Different Port In Linux
3 NOV, 2012
Linux Commad To List Directories / Directory
Names Only
2 NOV, 2012
Linux Usermod Command To Modify User
Details
20 OCT, 2012
Linux Command To Show / List All Users In the
System
18 OCT, 2012
Run Command In Linux - Run Shell With
Specified User / Group ID
2 OCT, 2012
Linux System Performance Monitoring Using
Sar Command
12 SEP, 2012
How To Mount & Umount Different Devices In
Linux
1 SEP, 2012
How To Use Linux Grep Command To Find
Strings
6 MAY, 2012
What Is Linux RPM And Installing, Uninstalling,
Updating, Querying,Verifying RPM
20 OCT, 2011
11 Examples How To Use Linux Tar Command
And All Options
7 SEP, 2011
Learn How To Use Linux vi Editor And Its
Commands
7 SEP, 2011
Linux Commands To Manage Shared Libraries
6 SEP, 2011
8 Examples - Linux du Command With All Its
Options
6 SEP, 2011
15 Difference Between Linux Yum and
Up2date Command
6 SEP, 2011
Example - How To Use Tee Command In Linux
22 AUG, 2011
13 Examples To Explain Linux Netstat Commad
22 AUG, 2011
Learn Linux DD Command - 15 Examples With
All Options
24 JUN, 2011
Linux Watch Command - Repeat A Command
At Regular Intervals
21 JUN, 2011
7 Examples Linux Dmidecode Command -
Display Hardware Details In BIOS
27 MAY, 2011
8 Examples For Linux Zip And UnZip Command
18 MAY, 2011
38 Basic Linux Commands To Learn With
Examples
16 MAY, 2011
Commands Check Linux OS is 64 / 32 bit and
CPU 64 / 32 Bit
13 MAY, 2011
Linux Print Command : Usage Of Linux lp
Command With Examples
10 MAY, 2011
6 Examples Linux Chage Command : Set
Password Aging For User
2 MAY, 2011
10 Example Scenarios To Learn Linux Find
Command
30 APR, 2011
Linux Awk Command With Examples To Make
It Easy
30 APR, 2011
What All Command Used To Find Architecture
Of Linux OS and CPU
30 APR, 2011
Linux Hdparm Command: Display Hard Disk
Model and Serial Number
24 APR, 2011
Everyday Linux ps command Examples for
System Admin
24 APR, 2011
How To List Linux Pci Devices Using lspci
Command
23 APR, 2011
How To Use Screen And Script Command In
Linux
23 APR, 2011
12 Different Options of Rsync Command in
Linux With Examples
23 APR, 2011
How To Use Linux Route Add Command
23 APR, 2011
Few Netstat Command Example Useful For
Daily Usage
23 APR, 2011
Can Linux sfdisk Tool Used Instead Of Fdisk
20 MAR, 2011
Can dd Command Used To Wipe Data?
Examples
20 MAR, 2011
How To Use Linux Kill Command
20 MAR, 2011
How To Backup LVM Configuration On Linux
(vgcfgbackup & vgcfgrestore)
25 FEB, 2011
How to Create Partition in Linux using fdisk
Tool
25 FEB, 2011
How To Use Linux Tr Command With Examples
22 FEB, 2011