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 a specified format, and then output it to a file, device, or standard output.
Parameter description:
- if=filename: Input file name; the default is standard input, i.e., the source file.
- of=filename: Output file name; the default is standard output, i.e., the destination file.
- ibs=bytes: Read bytes bytes at a time, specifying an input block size of bytes bytes.
obs=bytes: Write bytes bytes at a time, specifying an output block size of bytes bytes.
bs=bytes: Set both the input and output block sizes to bytes bytes. - cbs=bytes: Convert bytes bytes at a time, specifying the conversion buffer size.
- skip=blocks: Skip blocks blocks from the beginning of the input file before copying.
- seek=blocks: Skip blocks blocks from the beginning of the output file before copying.
- count=blocks: Copy only blocks blocks, with a block size equal to the number of bytes specified by ibs.
- conv=
, the keyword can be one of the following 11 types: - conversion: Convert the file using the specified parameters.
- ascii: Convert EBCDIC to ASCII
- ebcdic: Convert ASCII to EBCDIC
- ibm: Convert ASCII to alternate EBCDIC
- block: Convert each line to length cbs, padding short lines with spaces
- unblock: Make every line length cbs, padding short lines with spaces
- lcase: Convert uppercase characters to lowercase
- ucase: Convert lowercase characters to uppercase
- swap: Swap each pair of input bytes
- noerror: Do not stop on errors
- notrunc: Do not truncate the output file
- sync: Pad each input block to ibs bytes, filling shortfalls with null (NUL) characters.
- --help: Display help information
- --version: Display version information
Example
To create a boot disk under Linux, use the following command:
dd if=boot.img of=/dev/fd0 bs=1440k
To convert all English letters in the file testfile to uppercase and then write them to the file testfile_1, use the following command at the prompt:
dd if=testfile_2 of=testfile_1 conv=ucase
The contents of testfile_2 are:
$ 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, the contents of testfile_1 are 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中的所有字符都变成了大写字母
To read a string from standard input, convert it to uppercase, and then output it to standard output, use the following command:
dd conv=ucase
After entering the above command, press Enter, type a string, press Enter again, then press 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/s
Linux Command Reference