Five Useful Linux DD Examples
Linux dd is a common Linux program whose primary purpose is the low-level copying and conversion of raw data. You can backup whole hard drives, create a large file filled with only zeros, create and modify image files at specific points, and even do conversions to upper case.
To display dd’s help simply enter:
erik@debian:~$dd –help
Alright, lets get to the juicy stuff.
1. Create an ISO of a your favourite CD just for storage purposes with linux dd command:
dd if=/dev/cdrom of=/home/erik/myCD.iso bs=2048 conv=sync
Breaking down the linux dd command:
+ if is “input file”, so in this case our cdrom drive at /dev/cdrom
+ of is “output file”, in this case myCD.iso
+ bs is “block size”, in this case 2048 bytes per block
+ conv is for conversion, in this case we are using “sync” which tells DD to execute synchronized input and output, this is needed for the CD-ROM as we want to read a whole block to ensure no data loss occurs.
2. Replicate one hard disk partition to another hard disk with dd:
dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror
In this case everything is the same as example 1 but our conversion methods states that noerror should be executed, this tells DD to continue after read errors.
3. Create a file with 1MB of random bytes with dd:
erik@debian:~$dd if=/dev/urandom bs=1024 count=1000 of=fun.bin
1000+0 records in
1000+0 records out
1024000 bytes (1.0 MB) copied, 0.198349 s, 5.2 MB/s
This time I stated that our block size is 1024 bytes, and we are going to make 1000 of them sequentially. I also used the built-in kernel device urandom which provides random bytes.
4. Skip first 128K of input file then write remaining with dd:
dd if=/home/erik/fun.bin skip=128k bs=1 of=/home/erik/fun2.bin
The skip command tells DD to move passed the (in this case) 128k of data in fun.bin then write the rest to fun2.bin. This can be useful if you have a large file that needs to be written across more than one partition. For instance, if you had 3 partitions each 128k. You wouldn’t want to write the same 128k to each partition, you would want to write the first 128k to partition 1, then from 128k-256k of the file to partition 2 and so on.
5. Using dd to convert a file to uppercase:
dd if=erik.txt of=erik_up.txt conv=ucase
Finally, we use conv again to do a conversion. In this case we convert with the specifier of ucase.
What is your favourite use of the linux dd command?
I have used dd on more occasions then I can recall. It definitely is a tool that provides hard drive copying, backup, and replication without having to dig too deep into Linux internals. Another neat use of dd is to send data across a network socket, so you can use dd as the packet data generator with the socket pre opened.
If you are surfing for more info about the niche of internet marketing, then please check out the site that is quoted in this line.
Incoming search terms:
- co2 carbon capture sequestration
- dd examples
