The dd Command FAQs

April 2nd, 2009

Whosoever has worked in Unix environment must be aware of dd command. The specialty of dd command lies in fact that it can copy a file, convert character mapping of files and do various other operations. In this article I am going to introduce various uses of dd command in the form of FAQs. Although the options apply to all *nix based OS, but these are specifically related to AIX.

What Does dd Command Do
The dd command reads input file specified by “if” parameter and produces output file specified by “of” parameter. In the process of generating output file, it can take  several other parameters to fulfill the demands of output file. One more specific thing about dd is that, it copies the files block by block. Default block size is taken as OS block size.

What Are dd Command Common Parameters
The dd command has the following common parameters:

1. bs:                Block Size.
2. cbs:              Conversion Block Size. Used if block, unblock, ascii, ebcdic or ibm conversion is used. Its used for converting from variable block size devices to fixed block size devices.
3. conv:           Conversion format. It can be [ascii | block | ebcdic | ibm | unblock], [lcase |  ucase], [iblock],  [noerror], [swab], [sync], [oblock], [notrunc].
4. count:          Number of input blocks.
5. files:                        Input files.
6. fskip:           Skip EOF characterss.
7. ibs:               Input Block Size.
8. obs:              Output Block Size.
9. if:                 Input File.
10. of:                Output File.
11. seek:          Skip to record number specified.
12. skip:           Skip number of input blocks.
13. span:          [yes|no] This option is used if your file will span over multiple devices, if the input file is larger than output devices.

Now, for demo purpose I have created a file named as lower. I have added the text to this file.

How To Translate From Lower Case To Upper Case In A File
The following example will demonstrate how to translate a file from lowercase to uppercase and vice versa.

wiwlabs:$ cat lower
dd example for demonstrating translation.
wiwlabs:$ dd conv=ucase if=lower of=upper
0+1 records in
0+1 records out
wiwlabs:$ cat upper
DD EXAMPLE FOR DEMONSTRATING TRANSLATION.
wiwlabs:$ dd conv=lcase if=upper of=lower_case_file
0+1 records in
0+1 records out
wiwlabs:$ cat lower_case_file
dd example for demonstrating translation.

Another nice example is to use dd with pipe:


wsd007:$ cat lower|dd conv=ucase
DD EXAMPLE FOR DEMONSTRATING CONVERSION.
0+1 records in
0+1 records out
wsd007:$ cat upper|dd conv=lcase
dd example from demonstrating translation.
0+1 records in
0+1 records out


How To Create A Duplicate Copy of Diskette

wiwlabs:$  dd if=/dev/fd0 of=/tmp/fdcopy
2880+0 records in.
2880+0 records out.
wiwlabs:$  dd if=/tmp/fdcopy of=/dev/fd0
2880+0 records in.
2880+0 records out.


How To Convert An ASCII text file to EBCDIC Type And Vice-Versa

wiwlabs:$ cat lower
dd example for demonstrating conversion.
wiwlabs:$ dd conv=ebcdic if=lower of=text.ebcdic
0+1 records in
0+1 records out
wiwlabs:$ cat text.ebcdic
@
§
@@
¢££@¥
wiwlabs:$ dd if=text.ebcdic of=text.ascii conv=ascii
0+1 records in
0+1 records out
wiwlabs:$ cat text.ascii
dd example for demonstrating conversion.


How To Copy Blocks From A Tape With 2KB Blocks To Another With 1KB Blocks

dd if=/dev/rmt0  ibs=2048 obs=1024 of=/dev/rmt2


How To Copy Blocks From An Input File With Block Size 32k To Tape

dd if=some_large_file  bs=32k  of=/dev/rmt0 conv=sync  span=yes

Tags: , , , , , ,
Posted in Backups | 1 Comment »

Comments

One Response to “The dd Command FAQs”

  1. How To Recover A Superblock | World is Welcome To The World of Unix!!! Says:

    […] mount commands give errors then pretty good chances are there that the superblock is corrupt. The dd command comes to rescue. We know that the superblock resides in 31st block also. So, to recover […]

Leave a Reply

 Comment Form 

 



More articles from the category: Backups


The dd Command FAQs

Whosoever has worked in Unix environment must be aware of dd command. The specialty of dd command lies in fact that it can copy a file, convert character mapping of files and do various other operations. In this article I am going to introduce various uses of dd command in the form of FAQs…

Solving Incorrect Block Size Problem In Backup Tapes

Its common phenomena to take Unix tape backups on one system and restore on another. Moving tapes to another site for safety sake is also called offsite backup. The problem often occurs while restoring tape data on another server. The tape backup access is very much dependent upon the block size used on the Unix server. For example on one unix server the block size can be 2048 Bytes and on another it may be 1024 Bytes….

Restoring Files From Aix mksysb Backup

You may be aware that the mksysb command creates the bootable image of all the mounted files systems on rootvg, at the time of creation of mksysb image. Here I am going to discuss how to restore data from mksysb backup image. I’ll discuss how to restore single file, multiple files and directories from mksysb backup image….

How To Use mksysb Command

Here I am going to discuss what you can do with the mksysb command. But before proceeding further let’s have a look on important command line options. Consult mksysb man page from IBM for more information….

Some Interesting Facts About mksysb

While I was writing about mksysb notes from IBM manuals, I came to know of some interesting facts about mksysb command in the man pages. Not everyone is interested in navigating through man pages or so. Here, I’m presenting the facts in my own language…

All You Wanted To Know About AIX Tape Device Backups-II

Welcome to the second article of the series about rmt devices in AIX. In first article I discussed about the common but confusing terminology used for tape devices. I hope you found the article All You Wanted To Know About AIX Tape Device Backups-I, interesting and useful. In this second article I am gonna explain the other naming conventions for rmt tape devices…

All You Wanted To Know About AIX Tape Device Backups-I

The tape devices in AIX are designated as rmt devices. The rmt are specifically used for backups. During the study of AIX tape backups, lots of confusion arises in the terminology. Before discussing in detail about rmt tape types I would like to discuss these six confusing terms used in context to tape backups and restores…

What is mksysb And What Are Its Components

mksysb is a command to create backup of rootvg on AIX systems. It creates bootable image of all the filesystems mounted at the time of taking mksysb backup. And backup created …