Linux dd Command
The Linux dd command is used to read, convert, and output data.
dd can read data from standard input or a file, convert the data according to the specified format, and then output to a file, device, or standard output.
Parameter description:
- if=file name: input file name, defaults to standard input. That is, specify the source file.
- of=file name: output file name, defaults to standard output. That is, specify the destination file.
- ibs=bytes: read in bytes bytes at a time, i.e., specify a block size of bytes bytes.
obs=bytes: output bytes bytes at a time, i.e., specify a block size of bytes bytes.
bs=bytes: simultaneously set the input/output block size to bytes bytes. - cbs=bytes: convert bytes bytes at a time, i.e., specify the conversion buffer size.
- skip=blocks: skip blocks blocks from the beginning of the input file before starting to copy.
- seek=blocks: skip blocks blocks from the beginning of the output file before starting to copy.
- count=blocks: copy only blocks blocks, with block size equal to the number of bytes specified by ibs.
- conv=<keyword>, the keywords can be the following 11 types:
- 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 the insufficient part with spaces
- unblock: make each line's length cbs, padding the insufficient part with spaces
- lcase: convert uppercase characters to lowercase characters
- ucase: convert lowercase characters to uppercase characters
- swap: swap each pair of input bytes
- noerror: do not stop when an error occurs
- notrunc: do not truncate the output file
- sync: pad each input block to ibs bytes, filling the insufficient part with null (NUL) characters.
- --help: display help information
- --version: display version information
Examples
To create a boot disk under Linux, you can use the following command:
dd if=boot.img of=/dev/fd0 bs=1440k
Convert all English letters in the testfile file to uppercase, then convert it into the testfile_1 file, use the following command at the command prompt:
dd if=testfile_2 of=testfile_1 conv=ucase
The content of testfile_2 is:
$ cat testfile_2 #testfile_2的内容 HELLO LINUX! Linux is a free unix-type opterating system. This is a linux testfile! Linux test
After the conversion is completed, the content of testfile_1 is as follows:
$ dd if=testfile_2 of=testfile_1 conv=ucase #使用dd 命令,大小写转换记录了0+1 的读入 记录了0+1 的写出 95字节(95 B)已复制,0.000131446 秒,723 KB/s cmd@hdd-desktop:~$ cat testfile_1 #查看转换后的testfile_1文件内容 HELLO LINUX! LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM. THIS IS A LINUX TESTFILE! LINUX TEST #testfile_2中的所有字符都变成了大写字母
Read a string from the standard input device, convert the string to uppercase, and then output it to the standard output device. The command used is:
dd conv=ucase
After entering the above command, press the Enter key, input a string, press the Enter key again, and press the combination key Ctrl+D to exit. The following result appears:
$ dd conv=ucase Hello Linux! #输入字符串后按回车键 HELLO LINUX! #按组合键Ctrl+D退出,转换成大写结果 记录了0+1 的读入 记录了0+1 的写出 13字节(13 B)已复制,12.1558 秒,0.0 KB/sOther Extensions
Linux Command Encyclopedia