Common Linux commands - dd command

Online Linux command query tool

dd

Copy files and convert and format the contents of the original files

Additional information

The dd command is used to copy files and convert and format the contents of the original files. The dd command is very powerful. For some low-level problems, using the dd command can often get unexpected results. The most commonly used method is to use dd to back up raw devices. However, it is not recommended. If you need to back up Oracle raw devices, you can use rman backup or third-party software backup. If you use dd, it will be inconvenient to manage.
It is recommended to use dd to operate the physical disk when necessary. If it is a file system, it is more convenient to use other commands such as tar backup cpio. In addition, when using dd to operate on disk, it is best to use block device files.

grammar

dd(选项)

Options

bs=<字节数>:将ibs(输入)与obs(输出)设成指定的字节数;
cbs=<字节数>:转换时,每次只转换指定的字节数;
conv=<关键字>:指定文件转换的方式;
count=<区块数>:仅读取指定的区块数;
ibs=<字节数>:每次读取的字节数;
obs=<字节数>:每次输出的字节数;
of=<文件>:输出到文件;
seek=<区块数>:一开始输出时,跳过指定的区块数;
skip=<区块数>:一开始读取时,跳过指定的区块数;
--help:帮助;
--version:显示版本信息。

Example

[root@localhost text]# dd if=/dev/zero of=sun.txt bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.006107 seconds, 172 MB/s

[root@localhost text]# du -sh sun.txt 
1.1M    sun.txt

This command creates a 1M file sun.txt, in which the parameters are explained:

  • if represents the input file. If you do not specify if, input will be read from stdin by default.
  • of represents the output file. If of is not specified, stdout will be used as the default output by default.
  • bs represents the block size in bytes.
  • count represents the number of blocks copied.
  • /dev/zero is a character device and will continuously return 0-valued bytes (\0).
    Table of units of measurement that can be used for
    block size | unit size | code |
    | – | – |
    | Byte (1B) | c |
    | Byte (2B) | w | |
    Block (512B) | b | |
    Kilobyte ( 1024B) | k |
    | Megabyte (1024KB) | M |
    | Gigabyte (1024MB) | G |

The above command can see the dd command to test the memory operation speed:

1048576 bytes (1.0 MB) copied, 0.006107 seconds, 172 MB/s

Generate random strings
We can even use the /dev/urandom device with the dd command to get random strings.

[root@localhost ~]# dd if=/dev/urandom bs=1 count=15|base64 -w 0
15+0 records in
15+0 records out
15 bytes (15 B) copied, 0.000111993 s, 134 kB/s
wFRAnlkXeBXmWs1MyGEs

Online Linux command query tool

Online Linux command query tool

Guess you like

Origin blog.csdn.net/weixin_43251547/article/details/128597876