Linux dd Command
The Linux dd command is used to read, convert, and output data.
dd can read data from standard input or files, convert the data according to specified formats, and then output it to files, devices, or standard output.
Parameter Explanation:
if=filename: Input file name, default is standard input. Specifies the source file.
of=filename: Output file name, default is standard output. Specifies the destination file.
ibs=bytes: Read bytes number of bytes at a time, specifying a block size of bytes number of bytes.
cbs=bytes: Convert bytes number of bytes at a time, specifying the conversion buffer size.
skip=blocks: Skip blocks number of blocks at the beginning of the input file before starting to copy.
seek=blocks: Skip blocks number of blocks at the beginning of the output file before starting to copy.
count=blocks: Copy only blocks number of blocks, with block size equal to the bytes specified by ibs.
conv=<keyword>, keywords can be one of the following 11:
conversion: Convert the file with the specified parameters.
ascii: Convert EBCDIC to ASCII.
ebcdic: Convert ASCII to EBCDIC.
ibm: Convert ASCII to alternate EBCDIC.
block: Convert each line to a length of cbs, padding with spaces if necessary.
unblock: Ensure each line is of length cbs, padding with spaces if necessary.
lcase: Convert uppercase characters to lowercase.
ucase: Convert lowercase characters to uppercase.
swap: Swap every pair of input bytes.
noerror: Do not stop on errors.
notrunc: Do not truncate the output file.
sync: Pad each input block to ibs number of bytes, filling with null characters if necessary.
--help: Display help information.
--version: Display version information.
Example
To create a bootable disk on Linux, you can use the following command:
dd if=boot.img of=/dev/fd0 bs=1440k
To convert all English letters in the testfile to uppercase and save it as testfile_1, use the following command in the command prompt:
dd if=testfile_2 of=testfile_1 conv=ucase
Where the content of testfile_2 is:
$ cat testfile_2 # Contents of testfile_2
HELLO LINUX!
Linux is a free unix-type opterating system.
This is a linux testfile!
Linux test
After conversion, the content of testfile_1 is as follows:
$ dd if=testfile_2 of=testfile_1 conv=ucase # Using the dd command, uppercase conversion recorded 0+1 reads
0+1 writes recorded
95 bytes (95 B) copied, 0.000131446 seconds, 723 KB/s
cmd@hdd-desktop:~$ cat testfile_1 # View the converted content of testfile_1
HELLO LINUX!
LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM.
THIS IS A LINUX TESTFILE!
LINUX TEST # All characters in testfile_2 are converted to uppercase
To read a string from the standard input device, convert it to uppercase, and output it to the standard output device, use the command:
dd conv=ucase
After entering the command and pressing Enter, input the string, press Enter again, and then press Ctrl+D to exit, resulting in:
$ dd conv=ucase
Hello Linux! # Input the string and press Enter
HELLO LINUX! # Press Ctrl+D to exit, uppercase conversion result
0+1 reads recorded
0+1 writes recorded
13 bytes (13 B) copied, 12.1558 seconds, 0.0 KB/s