Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux dd command

Linux dd command

Linux Command Reference Linux Command Reference

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:

- 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.

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 Linux Command Reference