Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tutorial on using examples of dd commands in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces you about the use of the dd command in Linux, and shares it for your reference. Let's take a look at the detailed introduction:

First, the Linux dd command copies a file with a block of the specified size, and performs the specified conversion at the same time.

Usage: dd [OPERAND]

Parameter comments:

Bs=BYTES read and write BYTES bytes at a time (also see ibs= Obs=) cbs=BYTES convert BYTES bytes at a time conv=CONVS convert the file as per the comma separated symbol list count=N copy only N input blocks ibs=BYTES read BYTES bytes at a time (default: 512) if=FILE read from FILE instead of stdin (default is standard input) iflag=FLAGS read as per the comma separated symbol list obs=BYTES write BYTES bytes at a time (default: 512) of=FILE write to FILE instead of stdout (default is standard output) oflag=FLAGS write as per the comma separated symbol list seek=BLOCKS skip BLOCKS obs-sized blocks at start of output skip=BLOCKS skip BLOCKS ibs-sized Blocks at start of input status=WHICH WHICH info to suppress outputting to stderr 'noxfer' suppresses transfer stats, 'none' suppresses all

Optional parameters for CONVS

Ascii from EBCDIC to ASCII ebcdic from ASCII to EBCDIC ibm from ASCII to alternate EBCDIC block pad newline-terminated records with spaces to cbs-size unblock replace trailing spaces in cbs-size records with newline lcase change upper case to lower case nocreat do not create the output file excl fail if the output file already exists notrunc do not truncate the output file ucase change lower case to upper case sparse try to seek rather than write the output for NUL input blocks swab swap every pair of input bytes noerror continue after read errors sync pad every input block with NULs to ibs-size When used with block or unblock, pad with spaces rather than NULs fdatasync physically write output file data before finishing fsync likewise, but also write metadata

Optional parameters for FLAGS

Append append mode (makes sense only for output; conv=notrunc suggested) direct use direct direct use direct O for data directory fail unless a directory dsync use synchronized I count=N' as a byte count O for data sync likewise, but also for metadata fullblock accumulate full blocks of input (iflag only) nonblock use non-blocking I max O noatime do not update access time noctty do not assign controlling terminal from file nofollow do not follow symlinks count_bytes treat 'count=N' as a byte count (iflag only)

Note: if the specified number ends with the following characters, it will be multiplied by the corresponding number:

C = 1, w = 2, b = 512, kB = 1000, K = 1024, MB = 1000, M = 1024, xM = MGB = 1000, G = 1024, and so on for T, P, E, Z, Y

Second, use examples

1. Back up the local / dev/hdb to / dev/hdd

Dd if=/dev/hdb of=/dev/hdd

2. Back up the whole data of / dev/hdb to the image file of the specified path.

Dd if=/dev/hdb of=/root/image

3. Back up / dev/hdb the whole data, compress it with gzip tool and save it to the specified path.

Dd if=/dev/hdb | gzip > / root/image.gz

4. Split a file into 3 files

# the file size is 2.3k [Oracle@rhel6 ~] $ll db1_db_links.sql-rw-r--r-- 1 oracle oinstall 2344 Nov 21 10:39 db1_db_links.sql# split this file into each file 1kjm Oracle@rhel6 1k countdown 1 Use the skip parameter to specify how many bs branches are skipped in the input file to read [oracle@rhel6 ~] $dd if=db1_db_links.sql of=dd01.sql bs=1k count=11+0 records in1+0 records out1024 bytes (1.0 kB) copied, 4.5536e-05 s, 22.5 MB/s [oracle@rhel6 ~] $dd if=db1_db_links.sql of=dd02.sql bs=1k count=1 skip=11+0 records in1+0 records out1024 bytes (1.0 kB) copied, 0.000146387 s 7.0 MB/s [oracle@rhel6 ~] $dd if=db1_db_links.sql of=dd03.sql bs=1k count=1 skip=20+1 records in0+1 records out296 bytes (296B) copied, 0.000204216 s, 1.4 MB/s# split File [oracle@rhel6 ~] $ll dd*sql-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd01.sql-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd02.sql-rw-r--r-- 1 oracle oinstall 296 May 20 14:58 dd03.sql

5. Merge the split files into 1

# merge operation, where seek parameter is used Used to specify the number of bs skipped in the input file [oracle@rhel6 ~] $dd of=1.sql if=dd01.sql 2: 0 records in2+0 records out1024 bytes (1.0 kB) copied, 0.000176 s, 5.8 MB/s [oracle@rhel6 ~] $dd of=1.sql if=dd02.sql bs=1k seek=11+0 records in1+0 records out1024 bytes (1.0 kB) copied, 0.000124038 s, 8.3 MB/s [oracle@rhel6 ~] $dd of=1.sql if=dd03.sql bs=1k seek=20+1 records in0+1 records out296 bytes (296B) copied, 0.00203881 s Check [oracle@rhel6 ~] $diff 1.sql db1_db_ links.sql [oracle @ rhel6 ~] $with the pre-split file for kB/s#

6. Insert data at the specified location in the output file without truncating the output file

Need to use the conv=notrunc parameter

[oracle@rhel6 ~] $dd if=2.sql of=1.sql bs=1k seek=1 count=2 conv=notrunc

Summary

The above is the whole content of this article, I hope that the content of this article can bring some help to your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report