In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Linux common command dd, has a certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.
The dd command is used to read, convert, and output data. dd can read data from standard input or files, convert data according to the specified format, and then output to files, devices, or standard output.
Parameter description:
if= filename: Enter the filename, default to standard input. That is, specify the source file.
of= filename: output filename, default is standard output. That is, specify the destination file.
ibs=bytes: reads bytes bytes at a time, i.e. specifies 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: Set the block size of read/output to bytes at the same time.
cbs=bytes: converts bytes bytes at a time, i.e. specifies the conversion buffer size.
skip=blocks: skip blocks from the beginning of the input file before starting copying.
seek=blocks: Skip blocks from the beginning of the output file before starting copying.
count=blocks: copies only blocks, the block size is equal to the number of bytes specified by ibs.
conv=, keywords can have the following 11 kinds:
conversion: converts a file with 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, fill in any gaps with spaces
unblock: make each line cbs long, fill in any gaps with spaces
lcase: Convert upper-case characters to lower-case characters
ucase: convert lowercase characters to uppercase characters
swap: Swap each pair of bytes of input
noerror: Do not stop when there is an error
notrunc: Do not truncate output files
sync: Fill each input block to ibs bytes, filling in the gaps with NUL characters.
- help: Display help information
- version: Display version information
#### 1. Backup the entire local/dev/hdb disk to/dev/hdd
dd` `if``=``/dev/hdb` `of=``/dev/hdd### 2. Back up all data of/dev/hdb to image file of specified path
dd` `if``=``/dev/hdb` `of=``/root/image### 3. Restore backup files to specified disk
dd` `if``=``/root/image` `of=``/dev/hdb### 4. Backup/dev/hdb complete data, compress it with gzip tool, and save it to the specified path
dd` `if``=``/dev/hdb` `|``gzip` `> ``/root/image``.gz### 5. Restore compressed backup files to specified disk
gzip` `-``dc` `/root/image``.gz |``dd` `of=``/dev/hdb6. Backup and restore MBR 512 bytes of MBR information at the beginning of the backup disk to the specified file:
dd` `if``=``/dev/hda` `of=``/root/image` `count=1 bs=512count=1 means copy only one block;bs=512 means block size is 512 bytes.
Recovery:
dd` `if``=``/root/image` `of=``/dev/had Writes backup MBR information to the beginning of disk
#### 7. Backup floppy disk
dd` `if``=``/dev/fd0` `of=disk.img count=1 bs=1440k (i.e. block size is 1.44M)### 8. Copy memory contents to hard disk
dd` `if``=``/dev/mem` `of=``/root/mem``.bin bs=1024 (specified block size is 1k)### 9. Copy the contents of the CD to the specified folder and save it as a cd.iso file
dd` `if``=``/dev/cdrom``(hdc) of=``/root/cd``.iso10. Increase swap partition file size Step 1: Create a file of 256 MB size:
dd` `if``=``/dev/zero` `of=``/swapfile` `bs=1024 count=262144 Step 2: Turn this file into a swap file:
mkswap ``/swapfile Step 3: Enable this swap file:
swapon ``/swapfileStep 4: Edit the/etc/fstab file so that the swap file loads automatically every time you boot:
/swapfile` `swap default 0 0#### 11. Destroy disk data
dd` `if``=``/dev/urrandom ` `of=``/dev/hda1 Note: Use random data to fill the hard disk, which can be used to destroy data in some necessary cases.
#### 12. Test hard disk read/write speed
dd` `if``=``/dev/zero` `bs=1024 count=1000000 of=``/root/1Gb``.`` file``dd` `if``=``/root/1Gb``.`` file` `bs=64k |dd of = dev/null The command execution time output from the above two commands can be used to calculate the read and write speeds of the hard disk.
#### 13. Determine the best block size for your hard disk:
dd` `if``=``/dev/zero` `bs=1024 count=1000000 of=``/root/1Gb``.`` file` `dd` `if``=``/dev/zero` `bs=2048 count=500000 of=``/root/1Gb``.`` file` `dd` `if``=``/dev/zero` `bs=4096 count=250000 of=``/root/1Gb``.`` file` `dd` `if``=``/dev/zero` `bs=8192 count=125000 of=``/root/1Gb``.`` fileBy comparing the command execution times shown in the command output above, you can determine the optimal block size for your system.
#### 14. Repair hard disk:
dd` `if``=``/dev/sda` `of=``/dev/sda` ` or ``dd` `if``=``/dev/hda`of=``/dev/hda When the hard disk is left unused for a long time (more than one year), magnetic flux points will be generated on the disk. When the head reads these areas, it will encounter difficulties and may cause I/O errors. When this condition affects the first sector of the hard disk, it may cause the hard disk to be scrapped. The order above may bring these data back to life. And the process is safe and efficient.
#### 15. Remote backup using netcat
dd` `if``=``/dev/hda` `bs=16065b |netcat 1234 Execute this command on the source host to backup/dev/hda
netcat -l -p 1234 |``dd` `of=``/dev/hdc` `bs=16065b Execute this command on the destination host to receive data and write to/dev/hdc
netcat -l -p 1234 | ``bzip2` `> partition.img` `netcat -l -p 1234 |``gzip` `> partition.img The above two commands are changes to the target host command. Use bzip2 and gzip to compress the data respectively, and save the backup file in the current directory.
#### 16. Change the value of the ith byte in a large video file to 0x41 (i.e. ASCII value of capital letter A)
echo` `A |dd dd dd
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.