dd 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-dd
핵심 정리
- 입력(
if=, 기본 표준 입력)을 읽어 지정한 변환을 한 뒤 출력(of=, 기본 표준 출력)에 씁니다. 원시(raw) 장치에서 블록 크기를 정해 물리 I/O를 효율적으로 할 수 있습니다. - 크기 단위: 숫자 뒤
w(×2),b(×512),k(×1024),x나*로 곱하기.count는 바이트가 아니라 블록 수입니다. AIXdd는 GNU의M,G접미사를 받지 않습니다. - 자주 쓰는 형태:
dd if=/dev/zero of=/tmp/big bs=1024k count=1024(1GB 파일),dd if=/dev/rhdisk2 of=/dev/null bs=1024k count=1000(읽기 속도),dd if=/dev/rmt0 of=out bs=32k(테이프). conv=로ascii·ebcdic·ibm(문자 코드),lcase·ucase,block·unblock(고정·가변 길이 레코드),sync(입력 블록을 NULL로 채움),noerror(오류에도 계속),notrunc,swab을 줍니다.- 끝나면 읽고 쓴 전체·일부 블록 수를 보고합니다. 디스크 장치에
of=로 쓰면 그 내용이 덮어써지므로 장치 이름을 꼭 확인합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전의 내용이 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2 |
| 파일 | /usr/bin/dd |
| 관련 명령어 | cp, tar, cpio, backup, chdev(테이프 block_size) |
목적
파일을 변환하고 복사합니다.
영어 원문
Converts and copies a file.
구문
dd [ bs=BlockSize ] [ cbs=BlockSize ]
[ conv= [ ascii | block | ebcdic | ibm | unblock ] [ lcase | ucase ] [ iblock ] [ noerror ] [ swab ] [ sync ]
[ oblock ] [ notrunc ] ]
[ count=InputBlocks ] [ files=InputFiles ] [ fskip=SkipEOFs ] [ ibs=InputBlockSize ] [ if=InFile ]
[ obs=OutputBlockSize ] [ of=OutFile ] [ seek=RecordNumber ] [ skip=SkipInputBlocks ] [ span=yes|no ]
dd [ Option=Value ]
설명
dd 명령은 InFile이나 표준 입력을 읽어 지정한 변환을 한 뒤, 변환한 데이터를 OutFile이나 표준 출력에 복사합니다. 입출력 블록 크기를 정해 원시 물리 I/O를 활용할 수 있습니다.
참고: 블록은 dd가 한 번에 읽거나 쓰는 데이터의 양으로, 디스크 블록과 크기가 같지 않을 수 있습니다.
크기는 바이트 수로 줍니다. 숫자 끝에 w, b, k를 붙이면 각각 2, 512, 1024를 곱하고, 두 숫자를 x나 *로 이으면 곱한 값입니다. count는 바이트가 아니라 복사할 블록 수입니다.
conv=ascii와 conv=ebcdic의 문자 집합 대응은 서로 반대 동작으로, ASCII 문자와 대부분의 워크스테이션·키펀치에 있는 EBCDIC 부분 집합 사이를 대응합니다.
block, unblock, ascii, ebcdic, ibm 변환을 쓸 때는 cbs를 줍니다. unblock이나 ascii는 고정 길이를 가변 길이로, 그 밖에는 가변 길이를 고정 길이로 바꾸며, cbs가 고정 길이를 정합니다.
주의: cbs를 가장 작은 입력 블록보다 작게 주면 변환한 블록이 잘립니다.
끝나면 읽고 쓴 전체·일부 입출력 블록 수를 보고합니다.
참고:
- 보통 출력 파일의 쓰기 권한만 있으면 되지만, 출력이 직접 접근 장치가 아니고
seek를 쓰면 읽기 권한도 필요합니다. - 줄바꿈은
conv=ascii나conv=unblock일 때만 넣고, 채움은conv=ebcdic,conv=ibm,conv=block일 때만 합니다. - 테이프로 파일을 복사할 때는 되도록
dd대신 테이프용으로 만든backup,tar,cpio를 씁니다. 테이프 장치는rmt특수 파일을 봅니다. bs,ibs,obs의 블록 크기는 쓰는 매체의 물리 블록 크기의 배수여야 합니다.conv=sync를 주면 일부만 읽은 입력 블록을 NULL로 채웁니다. 그래서 읽기가ibs만큼 다 차지 않으면 데이터 중간에 NULL이 들어가며, 파이프에서 읽을 때 흔히 생깁니다.bs만 주고sync,noerror,notrunc말고 다른 변환이 없으면 입력 블록마다 출력 블록 하나로 씁니다. 이때sync없이 덜 찬 블록을 읽으면 출력 블록도 그 크기입니다.bs가 없거나 다른 변환이 있으면 입력을 모아 꽉 찬 출력 블록으로 씁니다.
장치를 넘나드는 복사
입력 파일이 출력 장치의 물리 크기보다 크면 dd가 여러 장치에 걸쳐 쓰게 할 수 있습니다(span=yes).
참고: 블록 크기 bs를 장치 물리 크기의 정확한 배수로 주지 않으면 데이터가 어긋나거나 겹칠 수 있으니 조심합니다.
InFile이나 OutFile이 표준 입력·출력이면 장치를 넘나들지 않습니다. 쓰는 중에 출력 장치가 차면 다음 장치를 넣으라고 묻습니다. 읽을 때는 장치 끝에 닿지 않았어도 데이터를 다 읽으면 다음 장치를 물으며, 이때 끝내려면 n을 누릅니다.
영어 원문
The dd command reads the InFile parameter or standard input, does the specified conversions, then copies the converted data to the OutFile parameter or standard output. The input and output block size can be specified to take advantage of raw physical I/O.
Note: The term Block refers to the quantity of data read or written by the dd command in one operation and is not necessarily the same size as a disk block.
Where sizes are specified, a number of bytes is expected. A number ending with w, b, or k specifies multiplication by 2, 512, or 1024 respectively; a pair of numbers separated by an x or an * (asterisk) indicates a product. The count parameter expects the number of blocks, not the number of bytes, to be copied.
The character-set mappings associated with the conv=ascii and conv=ebcdic flags are complementary operations. These flags map between ASCII characters and the subset of EBCDIC characters found on most workstations and keypunches.
Use the cbs parameter value if specifying any of the block, unblock, ascii, ebcdic, or ibm conversions. If unblock or ascii parameters are specified, then the dd command performs a fixed-length to variable-length conversion. Otherwise it performs a conversion from variable-length to fixed-length. The cbs parameter determines the fixed-length.
Attention: If the cbs parameter value is specified smaller than the smallest input block, the converted block is truncated.
After it finishes, the dd command reports the number of whole and partial input and output blocks.
Note:
Usually, you need only write access to the output file. However, when the output file is not on a direct-access device and you use the seek flag, you also need read access to the file.
The dd command inserts new-line characters only when converting with the conv=ascii or conv=unblock flags set; it pads only when converting with the conv=ebcdic, conv=ibm, or conv=block flags set.
Use the backup, tar, or cpio command instead of the dd command whenever possible to copy files to tape. These commands are designed for use with tape devices. For more information on using tape devices, see the rmt special file.
The block size values specified with the bs, ibs and obs flags must always be a multiple of the physical block size for the media being used.
When the conv=sync flag is specified, the dd command pads any partial input blocks with nulls. Thus, the dd command inserts nulls into the middle of the data stream if any of the reads do not receive a full block of data (as specified by the ibs flag). This is a common occurrence when reading from pipes.
If the bs flag is specified by itself and no conversions other than sync, noerror or notrunc are specified, then the data from each input block will be written as a separate output block; if the read returns less than a full block and sync is not specified, then the resulting output block will be the
same size as the input block. If the bs flag is not specified, or a conversion other than sync, noerror or notrunc is specified, then the input will be processed and collected into fullsized output blocks until the end of input is reached.
Spanning across devices
The dd can be made to span across devices if the input file is larger than the output device physical size.
Note: Care has to be taken when specifying the block size bs as exact multiple of the physical size of the device because improper block size will result in data inconsistency, or overlap.
The spanning of dd across devices will not occur if either one of the InFile or the OutFile parameter is stdin or stdout.
Spanning will occur in such a way that dd will prompt for next device during write if the output device is full. During read from the input device, dd will prompt for next device if the data is completely read from the input device even when the device has not reached the end. In this case it would be required to press 'n' to quit.
플래그
| 플래그 | 설명 |
|---|---|
bs=BlockSize |
입출력 블록 크기를 함께 정하며 ibs, obs보다 우선합니다. 매체 물리 블록 크기의 배수여야 합니다. |
cbs=BlockSize |
conv=block 같은 가변·고정 길이 변환의 변환 블록 크기. |
count=InputBlocks |
그 수만큼의 입력 블록만 복사합니다. |
conv=Conversion,... |
변환 옵션(쉼표로 나눔, 아래 표). |
files=InputFiles |
그 수만큼의 입력 파일을 복사하고 끝냅니다(자기 테이프 같은 입력에서만 의미 있음). |
fskip=SkipEOFs |
복사하기 전에 그 수만큼의 파일 끝(EOF)을 건너뜁니다. 여러 파일이 있는 테이프에서 위치를 잡을 때 씁니다. |
ibs=InputBlockSize |
입력 블록 크기(기본 512바이트). 매체 물리 블록 크기의 배수여야 합니다. |
if=InFile |
입력 파일 이름(기본 표준 입력). |
obs=OutputBlockSize |
출력 블록 크기(기본 512바이트). 매체 물리 블록 크기의 배수여야 합니다. |
of=OutFile |
출력 파일 이름(기본 표준 출력). |
seek=RecordNumber |
복사하기 전에 출력 파일 처음부터 그 레코드로 이동합니다. |
skip=SkipInputBlocks |
복사하기 전에 그 수만큼의 입력 블록을 건너뜁니다. |
span=yes|no |
yes면 장치를 넘나들며 복사하고, no면 기본대로 동작합니다. |
conv 옵션:
| 옵션 | 설명 |
|---|---|
ascii |
EBCDIC을 ASCII로. ebcdic, ibm, block, unblock과 함께 쓸 수 없습니다. |
block |
가변 길이 레코드를 cbs 길이의 고정 길이로. ascii, ebcdic, ibm, unblock과 함께 쓸 수 없습니다. |
ebcdic |
ASCII를 표준 EBCDIC으로. ascii, ibm, block, unblock과 함께 쓸 수 없습니다. |
ibm |
ASCII를 IBM판 EBCDIC으로. ascii, ebcdic, block, unblock과 함께 쓸 수 없습니다. |
iblock, oblock |
직접 접근 장치의 읽기·쓰기 오류로 잃는 데이터를 줄입니다. iblock이면 블록을 읽다 오류가 나면 더 작은 단위로 다시 읽으며, 입력 장치의 섹터 크기를 알면 섹터 단위로, 모르면 512바이트 단위로 읽습니다. ibs는 이 재시도 크기의 배수여야 하며, 데이터 손실을 섹터 하나로 줄입니다. oblock은 출력에 같은 일을 합니다. |
lcase, ucase |
영문자를 모두 소문자, 대문자로. |
noerror |
오류가 나도 멈추지 않습니다. |
notrunc |
출력 파일을 잘라 내지 않습니다. 쓰지 않은 블록은 그대로 남습니다. |
swab |
바이트를 두 개씩 바꿉니다. |
sync |
모든 입력 블록을 ibs 크기로 채웁니다. |
unblock |
고정 길이 블록을 가변 길이로(길이는 cbs). ascii, ebcdic, ibm, block과 함께 쓸 수 없습니다. |
영어 원문
- bs=BlockSize — Specifies both the input and output block size, superseding the ibs and obs flags. The block size values specified with the bs flag must always be a multiple of the physical block size for the media being used.
- cbs=BlockSize — Specifies the conversion block size for variable-length to fixed-length and fixed-length to variable-length conversions, such as conv=block.
- count=InputBlocks — Copies only the number of input blocks specified by the InputBlocks variable.
- conv= Conversion,.... — Specifies one or more conversion options. Multiple conversions should be separated by commas. The following list describes the possible options: ascii Converts EBCDIC to ASCII. This option is incompatible with the ebcdic, ibm, block, and unblock options. block Converts variable-length records to fixed-length. The length is determined by the conversion block size (cbs). This option is incompatible with the ascii, ebcdic, ibm, and unblock options. ebcdic Converts ASCII to standard EBCDIC. This option is incompatible with the ascii, ibm, block, and unblock options. ibm Converts ASCII to an IBM® version of EBCDIC. This option is incompatible with the ascii, ebcdic, block, and unblock options. iblock, oblock Minimize data loss resulting from a read or write error on direct access devices. If you specify the iblock variable and an error occurs during a block read (where the block size is 512 or the size specified by the ibs=InputBlockSize variable), the dd command attempts to reread the data block in smaller size units. If the dd command can determine the sector size of the input device, it reads the damaged block one sector at a time. Otherwise, it reads it 512 bytes at a time. The input block size ( ibs) must be a multiple of this retry size. This option contains data loss associated with a read error to a single sector. The oblock conversion works similarly on output. lcase Makes all alphabetic characters lowercase. noerror Does not stop processing on an error. notrunc Does not truncate the output file. Instead, blocks not explicitly written to output are preserved. ucase Makes all alphabetic characters uppercase. swab Swaps every pair of bytes. sync Pads every input block to the ibs value. unblock Converts fixed-length blocks to variable-length. The length is determined by the conversion block size (cbs). This option is incompatible with the ascii, ebcdic, ibm, and block options.
- files=InputFiles — Copies the number of files specified by the InputFiles variable value of input files before ending (makes sense only where input is a magnetic tape or similar device).
- fskip=SkipEOFs — Skips past the number of end-of-file characters specified by the SkipEOFs variable before starting to copy; this SkipEOFs variable is useful for positioning on multifile magnetic tapes.
- ibs=InputBlockSize — Specifies the input-block size; the default is 512 bytes or one block. The block-size values specified with the ibs flag must always be a multiple of the physical block size for the media being used.
- if=InFile — Specifies the input file name; standard input is the default.
- obs=OutputBlockSize — Specifies the output-block size; the default is 512 bytes or one block. The block size values specified with the obs flag must always be a multiple of the physical block size for the media being used.
- of=OutFile — Specifies the output file name; standard output is the default.
- seek=RecordNumber — Seeks the record specified by the RecordNumber variable from the beginning of output file before copying.
- skip=SkipInputBlocks — Skips the specified SkipInputBlocks value of input blocks before starting to copy.
span=yes|no— Allows spanning across devices if specifiedyesand works as default if specified asno. See Spanning Across Devices, for more information..
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 입력 파일을 성공적으로 복사함 |
| 0보다 큼 | 오류 |
영어 원문
This command returns the following exit values:
- 0 — The input file was copied successfully.
>0— An error occurred.
예제
| 명령 | 하는 일 |
|---|---|
dd if=text.ascii of=text.ebcdic conv=ebcdic |
ASCII 텍스트를 EBCDIC으로 바꿔 text.ebcdic에 저장. ASCII ^는 쓰지 않는 EBCDIC 문자(16진 9A)로, ASCII ~는 EBCDIC의 NOT 기호로 바뀜 |
dd if=/etc/passwd cbs=132 conv=ebcdic of=/tmp/passwd.ebcdic |
가변 길이 ASCII 파일을 132바이트 고정 길이 EBCDIC 레코드로 |
dd if=/tmp/passwd.ebcdic cbs=132 conv=ascii of=/tmp/passwd.ascii |
132바이트 레코드의 EBCDIC 파일을 가변 길이 ASCII 줄로 |
dd if=/etc/passwd cbs=132 conv=ibm of=/tmp/passwd.ibm |
가변 길이 ASCII 파일을 132바이트 고정 길이 IBM판 EBCDIC 레코드로 |
dd if=/dev/rmt0 ibs=1024 obs=2048 of=/dev/rmt1 |
1KB 블록 테이프를 2KB 블록으로 다른 테이프에 복사 |
ls -l | dd conv=ucase |
필터로 써서 현재 디렉터리 목록을 대문자로 |
dd if=Filename of=/dev/rfd0 bs=36b conv=sync |
3.5인치 1.4MB 디스켓에 512바이트 36블록(실린더 하나)씩 효율적으로 씀. 파일 크기가 블록 크기의 배수가 아니면 conv=sync가 필요. 입력이 파이프면 대부분을 NULL로 채우므로 하지 않음 |
dd if=testfile of=/dev/fd0 bs=720b conv=sync |
720b 블록으로 1.44MB 디스켓에 복사. 입력이 장치보다 크면 다음 장치를 물음 |
dd if=inputfile of=/dev/rmt0 bs=32k conv=sync |
32k 블록으로 테이프에 복사 |
dd if=/dev/rmt0 of=outfile bs=32k conv=sync |
테이프에서 32k 블록으로 현재 디렉터리의 파일에 복사 |
dd if=testfile of=/dev/fd0 bs=720b conv=sync span=yes |
위와 같되 디스켓 여러 장에 걸쳐 복사 |
dd if=inputfile of=/dev/rmt0 bs=32k conv=sync span=yes |
테이프 여러 개에 걸쳐 복사 |
dd if=/dev/rmt0 of=outfile bs=32k conv=sync span=yes |
여러 테이프에서 읽어 파일로 복사 |
9348 Magnetic Tape Unit Model 12에서는 기본 블록 크기를 바꿔 dd와 cpio의 성능을 높일 수 있습니다: chdev -l 장치이름 -a block_size=32k.
자주 쓰는 형태:
dd if=/dev/zero of=/tmp/test.img bs=1024k count=1024 # 1GB 파일 만들기
dd if=/dev/rhdisk2 of=/dev/null bs=1024k count=2000 # 원시 디스크 순차 읽기 속도
dd if=/dev/rhdisk2 of=/tmp/hdisk2.vgda bs=512 count=8192 # 디스크 앞부분 백업(VGDA 등)
dd if=/dev/rmt0 bs=32k | tar -tvf - # 블록 크기를 맞춰 테이프 읽기
영어 원문
- To convert an ASCII text file to EBCDIC, type:
dd if=text.ascii of=text.ebcdic conv=ebcdic
This command converts the text.ascii file to EBCDIC representation, storing the EBCDIC version in the text.ebcdic file.
Note: When you specify the conv=ebcdic parameter, the dd command converts the ASCII ^ (circumflex) character to an unused EBCDIC character (9A hexadecimal), and the ASCII ~ (tilde) to the EBCDIC ^ (NOT symbol).
- To convert the variable-length record ASCII file /etc/passwd to a file of 132-byte fixed-length EBCDIC records, type:
dd if=/etc/passwd cbs=132 conv=ebcdic of=/tmp/passwd.ebcdic
- To convert the 132-byte-per-record EBCDIC file to variable-length ASCII lines in lowercase, type:
dd if=/tmp/passwd.ebcdic cbs=132 conv=ascii of=/tmp/passwd.ascii
- To convert the variable-length record ASCII file /etc/passwd to a file of 132-byte fixed-length records in the IBM version of EBCDIC, type:
dd if=/etc/passwd cbs=132 conv=ibm of=/tmp/passwd.ibm
- To copy blocks from a tape with 1KB blocks to another tape using 2KB blocks, type:
dd if=/dev/rmt0 ibs=1024 obs=2048 of=/dev/rmt1
- To use the dd command as a filter, type:
ls -l | dd conv=ucase
This command displays a long listing of the current directory in uppercase.
Note: The performance of the dd command and cpio command to the 9348 Magnetic Tape Unit Model 12 can be improved by changing the default block size. To change the block size, use the chdev command in the following way:
chdev -l Device_name -a block_size=32k
- To perform efficient transfers to 3.5-inch 1.4MB diskette using 36 blocks of 512 bytes, type:
dd if=Filename of=/dev/rfd0 bs=36b conv=sync
This command writes the value of the Filename parameter to the diskette device a cylinder at a time. The conv=sync is required when reading from disk and when the file size is not a multiple of the diskette block size. Do not try this if the input to the dd command is a pipe instead of a file, it will pad most of the input with nulls instead of just the last block.
- To copy blocks from a input file with block size set to 720b blocks into a 1.44MB size diskette type:
dd if=testfile of=/dev/fd0 bs=720b conv=sync
Note: If the input file is larger than the physical size of the output device then dd will prompt you for another device.
- To copy blocks from a input file with block size set to 32k blocks to a tape type:
dd if=inputfile of=/dev/rmt0 bs=32k conv=sync
- To copy blocks of data from tape to a file in the current directory with block size set to 32k blocks type as follows:
dd if=/dev/rmt0 of=outfile bs=32k conv=sync
- To copy blocks from an input file with block size set to 720b, onto a 1.44MB size diskette, enter:
dd if=testfile of=/dev/fd0 bs=720b conv=sync span=yes
Note: If the input file is larger than the physical size of the output device, then dd will prompt you for another device.
- To copy blocks from an input file with block size set to 32k, to a tape, enter:
dd if=inputfile of=/dev/rmt0 bs=32k conv=sync span=yes
- To copy blocks of data from tape with block size set to 32k, to a file in the current directory, enter:
dd if=dev/rmt0 of=outfile bs=32k conv=sync span=yes
파일
| 파일 | 설명 |
|---|---|
/usr/bin/dd |
dd 명령 |
영어 원문
- /usr/bin/dd — Contains the dd command.
Related information:
- cp command
- tar command
- System backup
- Operating system files
리눅스(GNU)와 다른 점
리눅스의 GNU dd도 if=, of=, bs=, count=, skip=, seek=, conv=의 뜻이 같습니다. 다만 크기에 M, G(bs=1M) 접미사를 쓸 수 있고, status=progress(진행 표시), oflag=direct·iflag=direct(캐시 우회), conv=fsync가 있습니다. AIX에서는 캐시를 피하려고 /dev/rhdisk처럼 원시 장치를 씁니다. 장치를 넘나드는 span, files, fskip은 GNU dd에 없습니다.