cpio 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-cpio
핵심 정리
- 파일 이름 목록을 표준 입력으로 받아 아카이브를 만들거나(
-o), 아카이브에서 꺼내거나(-i), 다른 디렉터리로 복사합니다(-p). - 만들기:
find . -print | cpio -ov > /tmp/a.cpio, 목록:cpio -itv < /tmp/a.cpio, 꺼내기:cpio -idmv < /tmp/a.cpio, 디렉터리 복사:find . -print | cpio -pdmv /new/dir. - AIX
cpio의 플래그는-ov,-idmv처럼 대시 하나 뒤에 빈칸 없이 붙여 씁니다. 자주 쓰는 것은d(디렉터리 만들기),m(수정 시각 유지),v(이름 출력),t(목록),u(무조건 덮어쓰기),c(ASCII 헤더, 다른 시스템과 호환). - 기본 AIX
cpio는 2GB보다 큰 파일과 UID·GID 65,535 초과를 다루지 못합니다(6.1은-Hcrc로 4GB까지,g로 큰 ID). 큰 파일은tar,pax,backup을 씁니다. - System V 판
/usr/sysv/bin/cpio는-I·-O(아카이브 파일 지정),-A(덧붙이기),-k(손상된 헤더 건너뛰기),-Htar·-Hustar등을 지원합니다. 블록 장치보다 원시(raw) 장치로 출력합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 AIX cpio에 -H hdr(헤더 형식), g(큰 UID·GID), -Z(EFS 정보)가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1 |
| 파일 | /usr/bin/cpio, /usr/sysv/bin/cpio |
| 관련 명령어 | tar, pax, find, backup, restore, ls |
목적
파일을 아카이브 저장소와 디렉터리 사이로 복사합니다. 이 문서는 AIX cpio와 System V cpio를 함께 설명합니다.
영어 원문
Copies files into and out of archive storage and directories. This document describes the AIX cpio command and the System V cpio command.
구문
AIX cpio:
cpio -o [ a ] [ c ] [ -E {force|ignore|warn} ] [ g ] [ -H hdr ] [ -U ] [ v ] [ B | C Value ] [ -Z ] <FileName >Output
cpio -i [ b ] [ c ] [ d ] [ -E {force|ignore|warn} ] [ f ] [ -H hdr ] [ m ] [ M ] [ r ] [ s ] [ t ] [ -U ] [ u ] [ v ]
[ S ] [ 6 ] [ B | C Value ] [ -Z ] [ Pattern... ] <Input
cpio -p [ a ] [ d ] [ -E {force|ignore|warn} ] [ l ] [ m ] [ M ] [ -U ] [ u ] [ v ] [ -Z ] Directory <FileName
g, -H, -Z는 6.1 구문에만 있습니다. System V cpio의 구문은 아래 System V cpio 절에 있습니다.
설명
주의: cpio의 출력을 특수 파일(장치)로 보낼 때는 블록 장치가 아니라 원시(raw) 장치로 보냅니다. 블록 장치에는 비동기로 써서 장치 끝에 닿았는지 알 수 없기 때문입니다.
참고:
- XPG/4와 POSIX.2 표준의 제한 때문에
cpio는 2GB보다 큰 파일을 다루지 못합니다. cpio는 희소(sparse) 파일의 희소성을 보존하지 않아, 풀면 파일 크기만큼 공간을 모두 차지합니다.- (6.1) System V
cpio는 암호화 파일 시스템(EFS)에 쓸 수 없습니다.
cpio -o
표준 입력에서 파일 경로 이름을 읽어 그 파일들을 경로 이름, 상태 정보와 함께 표준 출력에 복사합니다. 하드 링크로 이어진 파일이 아주 많은 경로 목록은 피합니다. 메모리가 모자라 링크 정보를 잃을 수 있습니다.
cpio -i
cpio -o로 만든 아카이브를 표준 입력에서 읽어, 이름이 Pattern과 맞는 파일을 현재 디렉터리 트리로 복사합니다. Pattern은 ksh의 파일 이름 표기로 여러 개 줄 수 있으며, 여기서는 *, ?, [...]가 /와도 맞습니다. 기본은 *(모든 파일)입니다. [a-z]의 -는 현재 대조 순서에 따른 범위이며, 대조 순서는 문자 범위에 쓸 동치 클래스를 정할 수 있습니다.
cpio -p
표준 입력에서 파일 경로 이름을 읽어 Directory 디렉터리로 복사합니다. 디렉터리는 이미 있어야 하며, 경로에 없는 디렉터리가 있으면 d를 줘서 만들게 합니다.
참고: 특수 파일은 root만 복사할 수 있습니다.
cpio -U
AIX 5.3부터 cpio는 기본으로 확장 속성을 무시합니다. -U를 주면 ACL을 포함한 속성을 보관하고 되살립니다. 이를 위해 cpio 아카이브에 확장 속성 항목과 ACL 항목의 새 레코드 유형이 쓰입니다.
cpio 아카이브의 각 객체는 cpio 헤더와 그 객체의 데이터로 이루어집니다. 기본 바이너리 형식과 c 형식의 헤더는 다음과 같습니다.
| 필드 | 크기(바이트) | 쓰임 |
|---|---|---|
h_magic |
2 | 헤더를 알아보는 매직 번호 |
h_dev |
2 | 이 파일의 디렉터리 항목이 있는 장치 |
h_ino |
2 | 파일 시스템에서 입력 파일의 inode 번호 |
h_mode |
2 | 입력 파일의 모드(mode.h). POSIX는 다른 시스템으로 옮기지 않을 파일 유형에 0130000, 0150000~0170000을 남겨 둠 |
h_uid, h_gid |
2, 2 | 소유자의 사용자 ID, 그룹 ID |
h_nlink |
2 | 입력 파일의 링크 수 |
h_rdev |
2 | 입력 파일을 가져온 원격 장치 ID |
h_mtime |
4 | 데이터를 마지막으로 바꾼 시각 |
h_namesize |
2 | NULL을 포함한 경로 이름 길이 |
h_filesize |
4 | 파일 길이(바이트) |
h_name |
PATH_MAX |
NULL로 끝나는 경로 이름 |
ACL이 있는 파일은 그 파일 객체 바로 앞에 ACL을 나타내는 <header,data> 객체가 옵니다. 헤더의 h_mode를 0130000으로 해서 ACL 헤더임을 나타내고 누가 ACL을 쓸 수 있는지도 비트로 나타내며, 나머지 필드는 ACL을 가진 파일의 inode 값과 같습니다. 데이터는 ACL 자체로, 처음 64비트가 ACL 유형이고 바로 뒤에 ACL 값이 옵니다.
확장 속성(EA)마다 그 속성을 완전히 나타내는 <header,data> 객체가 하나 있습니다. 헤더의 h_mode를 0150000으로 해서 EA 헤더임을 나타내고, 필드는 확장 속성의 inode 값과 같되 h_name은 <NULL><EAName><NULL>입니다. 데이터는 eaHeader 다음에 속성 소유자의 경로 이름과 속성 데이터가 옵니다.
struct eaHeader {
char pathLen[12];
char dataLen[12];
};
영어 원문
Attention: If you redirect the output from the cpio command to a special file (device), you should redirect it to the raw device and not the block device. Because writing to a block device is done asynchronously, there is no way to know if the end of the device is reached.
Note:
The cpio command is not enabled for files greater than 2GB in size due to limitations imposed by XPG/4 and POSIX.2 standards.
cpio does not preserve the sparse nature of any file that is sparsely allocated. Any file that was originally sparse before the restoration will have all space allocated within the filesystem for the size of the file.
You cannot use the System V cpio command for Encrypted File Systems.
cpio -o Command
The cpio -o command reads file path names from standard input and copies these files to standard output, along with path names and status information. Avoid giving the cpio command path names made up of many uniquely linked files, as it may not have enough memory to keep track of them and would lose linking information.
cpio -i Command
The cpio -i command reads from standard input an archive file created by the cpio -o command and copies from it the files with names that match the Pattern parameter. These files are copied into the current directory tree. You can list more than one Pattern parameter, using the file name notation described in the ksh command. Note that in this application the special characters * (asterisk), ? (question mark), and [...] (brackets and ellipses) match the / (slash) in path names, in addition to their use as described in the ksh command. The default for the Pattern parameter is an * (asterisk), selecting all files in the Input. In an expression such as [a-z], the minus sign means through according to the current collating sequence.
A collating sequence can define equivalence classes for use in character ranges.
cpio -p Command
The cpio -p command reads file path names from standard input and copies these files into the directory named by the Directory parameter. The specified directory must already exist. If these path names include directory names that do not already exist, you must use the d flag to cause the specified directory to be created.
Note: You can copy special files only if you have root user authority.
cpio -U command
For AIX 5.3, the cpio command will ignore extended attributes by default. The -U option informs cpio to archive or restore attributes, which includes ACLs.
A new record type is required for extended attribute entries in cpio archive files. A new record type is also required for ACL entries in cpio archive files.
Each object in the cpio archive contains a cpio header followed by the data for the specified object.
The following table describes the cpio header for default binary format and the -c format::
Name of field Size (number of bytes) Use
h_magic 2 Magic number for identifying header. h_dev 2 Device that contains a directory entry for this file. h_ino 2 Inode number that identifies the input file to the file system. h_mode 2 Mode of the input file, as defined in the mode.h file. The POSIX standard has 0130000, 0150000 - 0170000 available for file types that are not to be transported to other systems. h_uid 2 User ID of the owner of the input file. h_gid 2 Group ID of the owner of the input file. h_nlink 2 Number of links that are connected to the input file. h_rdev 2 ID of the remote device from which the input file is taken. h_mtime 4 Time when data was last modified. h_namesize 2 Length of the pathname including the NULL. h_filesize 4 Length of the file in bytes. h_name PATH_MAX Null-terminated pathname.
Each file which has an ACL will have a <header,data> object immediately preceding the object itself which describes the ACL as follows:
Header for ACL The h_mode field set to 0130000 indicates the header describes an ACL. Additionally, the h_mode bits are set to indicate who can write the ACL. All other fields in the cpio header are set as for the inode of the file owning the ACL.
Data The data will be the ACL itself. The first 64-bits of the data will be the ACL type. It will be immediately followed by the ACL value.
Each extended attribute will have a single <header,data> object in the archive which completely describes the extended attribute as follows:
Header for EA The h_mode field set to 0150000 indicates an extended attribute header. All fields in the cpio header are set as for the inode of the extended attribute. Except the h_name field is set to <NULL><EAName><NULL>
Data: This is formatted to describe the owner of the extended attribute as well as the data for the extended attribute. There is a eaHeader followed by the pathname of the owner of the extended attribute, followed by the extended attribute data.
struct eaHeader {
char pathLen[12];
char dataLen[12];
};
매개변수
| 매개변수 | 설명 |
|---|---|
| Directory | 디렉터리. |
<FileName |
입력으로 쓸 파일 이름 목록. |
>Output |
출력 장치(디스켓, 파일 등). 테이프는 rmt 특수 파일을 봅니다. |
<Input |
입력 장치(cpio -o로 만든 Output). |
| Pattern | ksh의 파일 이름 패턴. 기본은 *(모든 파일). |
영어 원문
- Directory — Specifies the directory.
<FileName— Specifies a list of file names for the cpio command to use as input.>Output— Specifies the output device such as a diskette or file. For more information on using tape devices see the rmt special file.<Input— Specifies the input device (where Input is the Output file created by the cpio -o command). For more information on using tape devices, see the rmt special file.- Pattern — Specifies the pattern (as described in the ksh command) to be used with the command. The default for the Patternparameter is an
*(asterisk), selecting all the files in the Input.
플래그
모든 플래그는 빈칸 없이 붙여 씁니다. 모든 플래그를 -o, -i, -p 각각에 쓸 수 있는 것은 아닙니다.
| 플래그 | 설명 |
|---|---|
a |
원본 파일의 접근 시각을 원래대로 되돌립니다. |
b |
바이트와 하프워드를 모두 바꿉니다. 바이트나 하프워드 수가 홀수면 데이터를 잃을 수 있습니다. |
B |
레코드당 512바이트로 블록 입출력을 합니다. 테이프에서 B나 C를 쓸 때 블록 인수는 테이프의 물리 블록 크기의 배수여야 하고, 꺼낼 때는 테이프의 아카이브 크기보다 크면 안 됩니다. B와 C는 함께 쓸 수 없으며 둘 다 주면 마지막 것을 씁니다. |
c |
헤더를 ASCII 문자 형식으로 읽고 씁니다. c로 만든 아카이브는 c로 꺼내야 합니다. |
C Value |
레코드당 Value × 512바이트로 블록 입출력을 합니다. 예: C2는 1024바이트. |
d |
필요하면 디렉터리를 만듭니다. |
-E {force|ignore|warn} |
파일의 익스텐트 속성(공간 예약, 고정 익스텐트 크기)을 보존할 수 없을 때의 동작. force는 그 파일의 꺼내기·복사를 실패, ignore는 오류를 무시, warn(기본)은 경고. |
f |
Pattern과 맞는 파일을 뺀 모든 파일을 복사합니다. |
g |
보관할 때 큰 UID·GID(USHORT_MAX보다 큼)를 허락합니다. 환경 변수 CPIO_LARGE_UID=ON으로도 됩니다. 6.1부터 |
-H hdr |
hdr 형식으로 헤더를 읽고 씁니다. 대상과 원본 컴퓨터 종류가 다를 때 -H나 c를 씁니다. c, 6과 함께 쓸 수 없고, -H로 만든 아카이브는 -H로 꺼내야 합니다. 값은 crc(파일마다 체크섬을 더한 ASCII 헤더, 2GB보다 큰 파일을 4GB까지 다룸), odc(작은 기본 유형의 ASCII 헤더). 6.1부터 |
l |
되도록 복사 대신 링크를 만듭니다. cpio -p에만 씁니다. |
m |
이전 파일 수정 시각을 유지합니다. 디렉터리를 복사할 때는 동작하지 않습니다. |
M |
디렉터리를 복사할 때도 이전 수정 시각을 유지합니다. |
r |
파일 이름을 대화형으로 바꿉니다. 이름을 바꾸지 않으려면 마침표 하나를 넣고, Enter만 누르면 그 파일을 복사하지 않습니다. |
s |
바이트를 바꿉니다. cpio -i에만 씁니다. 바이트 수가 홀수면 데이터를 잃을 수 있습니다. |
S |
하프워드를 바꿉니다. cpio -i에만 씁니다. |
t |
목차를 만듭니다. 파일은 복사하지 않습니다. |
-U |
ACL과 확장 속성을 보관하고 꺼냅니다. 대상 파일 시스템이 그 ACL 유형을 지원하지 않으면 지원하는 유형으로 바꾸고, EA를 지원하지 않으면 복사하지 않습니다. |
u |
무조건 복사합니다. 같은 이름의 새 파일을 오래된 파일로 바꿉니다. |
v |
파일 이름을 나열합니다. t와 함께면 ls -l과 비슷하게 보입니다. |
6 |
예전 파일(UNIX 6판 형식 등)을 처리합니다. cpio -i에만 씁니다. |
-Z |
EFS 파일·디렉터리의 EFS 정보를 보관합니다. 꺼낼 때는 EFS 정보를 꺼냅니다. t·v와 함께면 암호화 파일 모드 뒤에 e, 다른 파일은 -가 보입니다. -Z로 만든 아카이브는 AIX 6.1 이후에서만 풀 수 있습니다. 6.1부터 |
영어 원문
All flags must be listed together, without any blanks between them. Not all of the following flags can be used with each of the -o, -i, and -p flags.
- a — Resets the access times of the source files to their previous times.
- b — Swaps both bytes and halfwords. Note: If there is an odd number of bytes or halfwords in the file being processed, data can be lost.
- B — Performs block input and output using 512 bytes to a record. Note: When using the B or C options to extract or create a tape archive, the blocking factor must be a multiple of the physical block size for that tape device. When using the B or C options to extract an archive from tape, the blocking factor should not be larger than the size of the archive as it exists on the tape. The B flag and the C flag are mutually exclusive. If you list both, the cpio command uses the last one it encounters in the flag list.
- c — Reads and writes header information in ASCII character form. If a cpio archive was created using the c flag, it must be extracted with c flag.
- C Value — Performs block input and output using the Value parameter times 512 bytes to a record. For instance, a
-C2flag changes the block input and output sizes to 1024 bytes to a record. - d — Creates directories as needed.
-E— The-Eoption requires one of the following arguments. If you omit the-Eoption, warn is the default cpio behavior. force Fails the extract or copy operation on a file if the file's extent attributes cannot be preserved. ignore Ignores any errors in preserving extent attributes. warn Issues a warning if the space reservation or the fixed extent size of the file cannot be preserved. This is the default behavior.- f — Copies all files except those matching the Pattern parameter.
- g — Allows the large UID or GID (>
USHORT_MAX) values while archiving. Note: The environment variable can also be used for the same. UsageExport CPIO_LARGE_UID=ON - H — Reads or writes header information in hdr format. Either the
-Hor-coption can be used when the target and the destination computers are of different types. This option is mutually exclusive with the-cand-6options. This format allows system interoperability and portability. The cpio utility supports the archival of files larger than 2 GB in size when the CRC (-Hcrc) format is used. If a cpio archive is created by using the H flag, it must be extracted with the H flag. The valid values for the hdr variable are: crc Same as CRC. ASCII header with an additional per-file checksum. The crc file format handle files larger than 2 GB and maximum size supported is 4 GB. odc ASCII header with small fundamental types. - l — Links files rather than copying them, whenever possible. This flag can only be used with the cpio -p command.
- m — Retains previous file modification time. This flag does not work when copying directories.
- M — Retains previous file modification time even when directories are copied.
- r — Renames files interactively. If you do not want to change the file name, enter a single period or press the
<Enter>key. In the latter case, the cpio command does not copy the file. - s — Swaps bytes. This flag is used only with the cpio -i command. Note: If there is an odd number of bytes in the file being processed, data can be lost.
- S — Swaps halfwords. This flag is usable only with the cpio -i command. Note: If there is an odd number of halfwords in the file being processed, data can be lost.
- t — Creates a table of contents. This operation does not copy any files.
-U— Performs archival and extraction of ACL and Extended Attributes. Attributes include Access control list (ACL) also. If the ACL type is not supported on the Target filesystem then it is converted to the ACL type supported by the Target filesystem. If the EA is not supported on the filesystem then it is not copied.- u — Copies unconditionally. An older file now replaces a newer file with the same name.
- v — Lists file names. If you use this with the t flag, the output looks similar to that of the ls -l command.
- 6 — Processes an old file (for example, one written in UNIX Sixth Edition format). This flag is usable only with the cpio
-icommand. -Z— Archives the Encrypted File System (EFS) information of encrypted files or directories. The EFS information is extracted. When you specify the-tand-vflags along with the-Zflag, an e indicator is displayed after the file mode for encrypted files and directories that were archived with the-Zflag, and a hyphen (-) is displayed for other files. Note: Archives created with the-Zflag can be restored only on AIX 6.1 or later releases.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 성공 |
| 0보다 큼 | 오류 |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
보안
RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다(6.1 문서에만 있음).
영어 원문
Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
예제
| 명령 | 하는 일 |
|---|---|
cpio -ov <filenames >/dev/rfd0 |
파일 filenames에 경로가 적힌 파일들을 디스켓에 압축된 형태로 복사하며 이름을 보여 줌. 디스켓은 포맷되어 있어야 하지만 파일 시스템이 있거나 마운트되어 있으면 안 됨 |
ls *.c | cpio -ov >/dev/rfd0 |
현재 디렉터리에서 .c로 끝나는 파일을 디스켓에 복사 |
find . -print | cpio -ov >/dev/rfd0 |
현재 디렉터리부터 하위 디렉터리와 파일까지 디스켓에 저장. find . -cpio /dev/rfd0 -print가 더 빠름 |
cpio -itv </dev/rfd0 |
디스켓에 저장한 파일 목차(ls -l과 비슷). 경로만 보려면 -it |
cpio -idmv </dev/rfd0 |
디스켓의 파일을 파일 시스템에 되살림. d는 디렉터리를 만들고 m은 저장할 때의 수정 시각을 유지 |
cpio -i "*.c" "*.o" </dev/rfd0 |
.c, .o로 끝나는 파일만 꺼냄. 셸이 *를 해석하지 않게 따옴표로 감쌈 |
cpio -ir </dev/rfd0 |
꺼낼 때마다 Rename <prog.c>처럼 새 이름을 물음. 같은 이름이면 다시 입력하고, Enter만 누르면 복사하지 않음 |
ls *.c | cpio -oUv >/dev/rfd0 |
ACL과 EA를 보존하며 디스켓에 복사 |
참고: UID·GID가 65535보다 큰 파일은 cpio로 보관할 수 없으니 backup과 restore를 씁니다.
디렉터리와 하위 디렉터리를 모두 복사합니다. l은 되도록 복사 대신 링크를 만듭니다.
mkdir /home/jim/newdir
find . -print | cpio -pdl /home/jim/newdir
9348 Magnetic Tape Unit Model 12에서는 기본 블록 크기를 바꿔 성능을 높일 수 있습니다: chdev -l 장치이름 -a block_size=32k.
자주 쓰는 형태:
cd /data && find ./app -print | cpio -ov > /backup/app.cpio
cpio -itv < /backup/app.cpio | more
cd /restore && cpio -idmv < /backup/app.cpio
find . -depth -print | cpio -pdmv /newfs/app # 권한·시각을 유지하며 디렉터리 복사
영어 원문
- To copy files onto diskette, enter:
cpio -ov <filenames >/dev/rfd0
This copies the files with path names listed in the filenames file in a compact form onto the diskette (>/dev/rfd0). The v flag causes the cpio command to display the name of each file as it is copied. This command is useful for making backup copies of files. The diskette must already be formatted, but it must not contain a file system or be mounted.
Note: Files with uid's and gid's greater than 65535 cannot be archived using the cpio command. In such instances, the user should use backup and restore.
- To copy files in the current directory onto diskette, enter:
ls *.c | cpio -ov >/dev/rfd0
This copies all the files in the current directory whose names end with .c
- To copy the current directory and all subdirectories onto diskette, enter:
find . -print | cpio -ov >/dev/rfd0
This saves the directory tree that starts with the current directory (.) and includes all of its subdirectories and files. Do this faster by entering:
find . -cpio /dev/rfd0 -print
The -print entry displays the name of each file as it is copied.
- To list the files that have been saved onto a diskette with the cpio command, enter:
cpio -itv </dev/rfd0
This displays the table of contents of the data previously saved onto the /dev/rfd0 file in the cpio command format. The listing is similar to the long directory listing produced by the ls -l command. To list only the file path names, use only the -it flags.
- To copy the files previously saved with the cpio command from a diskette, enter:
cpio -idmv </dev/rfd0
This copies the files previously saved onto the /dev/rfd0 file by the cpio command back into the file system (specify the -i flag). The d flag allows the cpio command to create the appropriate directories if a directory tree is saved. The m flag maintains the last modification time in effect when the files are saved. The v flag causes the cpio command to display the name of each file as it is copied.
- To copy selected files from diskette, enter:
cpio -i "*.c" "*.o" </dev/rfd0
This copies the files that end with .c or .o from diskette. Note that the patterns "*.c" and "*.o" must be enclosed in quotation marks to prevent the shell from treating the * (asterisk) as a pattern-matching character. This is a special case in which the cpio command itself decodes the pattern-matching characters.
- To rename files as they are copied from diskette, enter:
cpio -ir </dev/rfd0
The -r flag causes the cpio command to ask you whether to rename each file before copying it from diskette. For example, the message: Rename <prog.c>
asks whether to give the file saved as prog.c a new name as it is copied. To rename the file, type the new name and press the Enter key. To keep the same name, you must enter the name again. To avoid copying the file at all, press the Enter key.
- To copy a directory and all of its subdirectories, enter:
mkdir /home/jim/newdir find . -print | cpio -pdl /home/jim/newdir
This duplicates the current directory tree, including the current directory and all of its subdirectories and files. The duplicate is placed in the new /home/jim/newdir directory. The l flag causes the cpio command to link files instead of copying them, when possible.
Note: The performance of cpio to the 9348 Magnetic Tape Unit Model 12 can be improved by changing the default block size. To change the block size, enter the following at the command line:
chdev -1 <device_name> -a block_size=32k
- To copy files in the current directory onto diskette and preserve the ACL and EA associated with the files, enter:
ls *.c | cpio -oUv >/dev/rfd0
파일
| 파일 | 설명 |
|---|---|
/usr/bin/cpio |
cpio 명령 |
영어 원문
- /usr/bin/cpio — Contains the cpio command.
System V cpio Command
AIX에는 System V 방식의 cpio가 /usr/sysv/bin/cpio로 따로 들어 있습니다. 플래그는 대시를 붙여 쓰며, AIX cpio와 뜻이 다른 것이 있습니다.
영어 원문
목적
파일을 아카이브 저장소와 디렉터리 사이로 복사합니다.
영어 원문
Copies files into and out of archive storage and directories.
구문
cpio -i [ -b ] [ -B ] [ -c ] [ -d ] [ -f ] [ -k ] [ -m ] [ -r ] [ -s ] [ -S ] [ -T ] [ -t ] [ -u ] [ -v ] [ -V ] [ -6 ]
[ -C bufsize ] [ -E file ] [ -H hdr ] [ -I file [ -M message ] ] [ -R ID ] [ Patterns ... ]
cpio -o [ -a ] [ -A ] [ -B ] [ -c ] [ -L ] [ -v ] [ -V ] [ -C bufsize ] [ -H hdr ] [ -K mediasize ] [ -O file [ -M message ] ]
cpio -p [ -a ] [ -d ] [ -l ] [ -L ] [ -m ] [ -u ] [ -v ] [ -V ] [ -R ID ] Directory
설명
cpio는 파일을 아카이브로 복사해 넣거나 꺼냅니다. -i, -o, -p로 동작을 고르며 셋은 함께 쓸 수 없습니다.
cpio -i(copy in): -I를 주지 않았으면 표준 입력에서 이전 cpio -o의 결과물을 읽어 파일을 꺼냅니다. 이름이 Patterns와 맞는 파일만 고릅니다. Patterns는 ksh의 파일 이름 표기 정규식으로, ?, *, [...]가 /와도 맞고, \는 이스케이프 문자, !는 부정입니다(예: [!abc]는 a, b, c로 시작하지 않는 파일). 여러 패턴을 줄 수 있고 없으면 *(모든 파일)입니다. 현재 디렉터리의 파일 이름으로 바뀌지 않도록 패턴은 큰따옴표로 감쌉니다. 꺼낸 파일은 옵션에 따라 현재 디렉터리 트리에 만들어집니다.
파일 권한은 이전 cpio -o 때의 것입니다. 소유자와 그룹은 현재 사용자가 root가 아니면 현재 사용자가 되고, root면 이전 cpio -o 때의 것이 됩니다. 블록 수는 512바이트 단위로 보고합니다.
이미 있는 파일을 만들려 할 때, 기존 파일이 같은 나이이거나 더 새것이면 경고를 내고 바꾸지 않습니다. 아카이브의 파일보다 기존 파일이 오래되었으면 경고 없이 바꿉니다.
cpio -o(copy out): 표준 입력에서 경로 이름 목록을 읽어 그 파일들을 경로 이름, 상태 정보와 함께 표준 출력에 복사합니다.
cpio -p(copy pass): 표준 입력에서 경로 이름 목록을 읽어 Directory로 복사합니다. 디렉터리는 이미 있어야 하고, 없는 디렉터리를 만들려면 -d를 줍니다. 이 옵션에서만 기본으로 ACL을 원본에서 대상으로 복사합니다.
영어 원문
The cpio command copies files into and out of an archive. The -i, -o and -p options select the action to be performed. The following list describes each of the actions. The -o, -p and -i options are mutually exclusive.
cpio -i (copy in)
cpio -i (copy in) extracts files from the standard input (only if -I is not specified), which is assumed to be the product of a previous cpio -o. Only files with names that match Patterns are selected. Patterns are regular expressions given in the filename generating notation of ksh. In Patterns, meta-characters "?", "*", and "[ . . . ]" match the slash ("/") character, and backslash ("\") is an escape character. A "!" meta-character means not. (For example, the "[!abc]" pattern would exclude all files that begin with either a, b or c.) Multiple patterns may be specified and if no patterns are specified, the default for Patterns is "*" (that is, select all files). Each pattern must be enclosed in double quotes; otherwise, the name of a file in the current directory might be used. Extracted files are conditionally created and copied into the current directory tree based on the options described below.
The cpio -i command reads the standard input of an archive file created that was using the cpio -o command, and copies the files with names that match the pattern parameter. The pattern parameter is a regular expression given with general notation of ksh. These files are copied into the current directory tree. More than one pattern parameter can be used, using the file name notation described in the ksh command. The patterns can be special characters * (asterisk), ? (question mark), and [...] (brackets and ellipses). The default for the pattern parameter is an * (asterisk), selecting all files in the input. In an expression such as [a-z], the minus sign means through according to the current collating sequence.
The permissions of the files will be those of the previous cpio -o. Owner and group permissions will be the same as the current user unless the current user is the root user. If this is true, owner and group permissions will be the same as those resulting from the previous cpio -o. Blocks are reported in 512-byte quantities.
If cpio -i tries to create a file that already exists and the existing file is the same age or younger (newer), cpio will output a warning message and not replace the file. On the other hand if the file being extracted is older than the one in the cpio archive then the existing file will be replaced without any warning from the command.
cpio -o (copy out)
cpio -o reads the standard input to obtain a list of path names and copies those files onto the standard output together with path name and status information.
cpio -p (copy pass)
cpio -p reads the standard input to obtain a list of path names of files and copies these files into the directory named by the Directory parameter. The specified directory must already exist. If these path names include directory names that do not already exist, you must use the d flag to cause the specified directory to be created. By default the Access Control List's (ACL) are transferred [copied] from source file to destination file with this option only.
플래그
| 플래그 | 설명 |
|---|---|
-a |
원본 파일의 접근 시각을 원래대로 되돌립니다. |
-A |
아카이브에 파일을 덧붙입니다. -O가 있어야 하며 rmt 특수 파일과 디스켓에는 쓸 수 없습니다. |
-b |
워드 안의 바이트 순서를 뒤집습니다. -i에만 씁니다. |
-B |
입출력 버퍼를 5120바이트로 합니다. 이것도 -C도 없으면 기본 512바이트입니다. |
-c |
시스템 간 호환을 위해 헤더를 ASCII 문자 형식으로 읽고 씁니다. -H, -6과 함께 쓸 수 없습니다. |
-C bufsize |
입출력 블록 크기를 bufsize(양의 정수)로 합니다. -K와 함께면 1K의 배수여야 합니다. |
-d |
필요하면 디렉터리를 만듭니다. |
-E file |
아카이브에서 꺼낼 파일 이름을 한 줄에 하나씩 적은 입력 파일. |
-f |
Patterns에 있는 것을 뺀 모든 파일을 꺼냅니다. |
-H hdr |
hdr 형식으로 헤더를 읽고 씁니다. -c, -6과 함께 쓸 수 없습니다. ASCII(-c), CRC(-Hcrc), tar(-Htar), ustar(-Hustar) 형식이면 2GB보다 큰 파일도 보관합니다. 값은 crc(파일마다 체크섬을 더한 ASCII 헤더), ustar(IEEE/P1003 데이터 교환 표준), tar(tar 헤더와 형식, tar와 호환), odc(작은 기본 유형의 ASCII 헤더). |
-I file |
파일 내용을 입력 아카이브로 읽습니다. 문자 특수 장치이고 지금 매체를 다 읽었으면 매체를 바꾸고 Enter를 눌러 계속합니다. -i에만 씁니다. |
-k |
손상된 파일 헤더와 I/O 오류를 건너뛰어 헤더가 성한 파일만 읽습니다. -i에만 씁니다. |
-K mediasize |
매체 크기(1K의 배수). -C와 함께면 bufsize도 1K의 배수여야 합니다. |
-l |
되도록 하드 링크를 만들고, 링크할 수 없으면 복사합니다. -p에만 씁니다. |
-L |
링크를 만들지 않고 링크가 가리키는 파일 내용을 링크 이름으로 복사합니다. -L도 -l도 없으면 -p의 기본대로 심볼릭 링크를 그대로 둡니다. |
-m |
이전 수정 시각을 유지합니다. 꺼낸 파일의 수정·접근 시각을 백업할 때의 수정 시각으로 합니다. 디렉터리의 수정 시각은 유지하지 않습니다. |
-M message |
매체를 바꿀 때 보여 줄 메시지. -O나 -I로 특수 장치를 쓸 때 매체 끝에서 나오며, %d를 넣으면 다음 매체 번호를 보여 줍니다. |
-O file |
출력을 파일로 보냅니다. 특수 장치이고 지금 매체가 차면 매체를 바꾸고 Enter를 눌러 계속합니다. -o에만 씁니다. |
-r |
파일 이름을 대화형으로 바꿉니다. 건너뛰려면 Enter, 원래 경로를 유지하려면 .을 입력합니다. -i에만 씁니다. |
-R ID |
파일마다 소유자와 그룹을 그 사용자 ID로 바꿉니다. root만 씁니다. |
-s |
하프워드 안의 바이트를 바꿉니다. |
-S |
워드 안의 하프워드를 바꿉니다. |
-t |
목차를 만듭니다. 파일은 만들지 않습니다. -V와 함께 쓸 수 없습니다. |
-T |
긴 파일 이름을 14자로 자릅니다. -i에만 씁니다. |
-u |
무조건 복사합니다(보통은 오래된 파일이 같은 이름의 새 파일을 바꾸지 않음). |
-v |
파일 이름 목록을 출력합니다. -t와 함께면 ls -l처럼 보입니다. |
-V |
파일 이름 대신 읽거나 쓴 파일마다 점 하나를 출력합니다. -v와 함께 쓸 수 없으며 먼저 나온 것을 씁니다. |
-6 |
UNIX 6판 아카이브 형식을 처리합니다. -c, -H와 함께 쓸 수 없습니다. |
영어 원문
-a— Resets the access time of the source files to their previous times.-A— Appends files to an archive. The-Aoption requires the-Ooption. The append option-Ais not valid for the rmt special file and diskettes.-b— Reverse the order of the bytes within each word. This option is valid only with the-ioption.-B— The default buffer size is 512 bytes when neither this nor the-Coption is used. But when-Bflag is used the buffer size is set to 5120 bytes block for the Input/Output operations.-c— Read or write header information in ASCII character form for system interoperability and portability. The-coption is mutually exclusive with-Hand-6. Either the-cor-Hoption can be used when the target and destination machines are different types.-Cbufsize — The block size for Input/Output operation is set to bufsize, where bufsize indicates the buffer size in positive integer. If used with-K, bufsize must be a multiple of 1K.-d— Creates directories as needed.-Efile — Specify an input file (file) that contains a list of file names to be extracted from the archive with one file name per line.-f— Copy in all files except those in Pattern parameter.-Hhdr — Read or write header information in hdr format. Either the-hor-coption can be used when the target and the destination machines are different types. This option is mutually exclusive with the-cand-6options. This format allows system interoperability and portability. The cpio utility supports the archival of files larger than 2 GB in size when using the ASCII (-c), CRC (-Hcrc), tar (-Htar), or ustar (- Hustar) formats. Valid values for hdr are: crc Same as CRC. ASCII header with an additional per-file checksum. The crc file format will handle files larger than 2 GB. ustar Same as USTAR. IEEE/P1003 Data Interchange Standard header and format. tar Same as TAR. Tar header and format. The tar format is provided for compatibility with the tar program. odc ASCII header with small fundamental types.-Ifile — Read the contents of file as an input archive. If file is a character special device, and the current medium has been completely read, replace the medium and press the Enter key to continue to the next medium. This option is valid only with the-ioption.-k— Attempt to skip corrupted file headers and I/O errors that may be encountered. This option lets the user read only those files with good headers if files from a medium that is corrupted. This option is valid only with the-ioption.-Kmediasize — Specify the media size as a multiple of 1K. If used with-Cbufsize, then bufsize must be a multiple of 1K.-l— Hard links files rather than copying them, whenever possible. If a file cannot be linked, then it will be copied. This option is valid only with-poption.-L— This option assists in copying the files rather than linking. The content of the link file is copied with the links name. Without-Lor-loption, the symbolic links will be maintained as is default with-p.-m— Retain previous file modification time. The modification time and access time of a restored file is set to the modification time of the file when it was backed up. Modification time of directories is not retained.-Mmessage — Define a message to use when switching media. When the-Oor-Ioptions are given cpio on a special device, this option can be used to define the message that is printed when you reach the end of the medium. A %d can be placed in message to print the sequence number of the next medium needed to continue.-Ofile — Direct the output of cpio to file. If file is a special device and the current medium is full, replace the medium and type Enter to continue to the next medium. This option is valid only with the-ooption.-r— Renames files interactively. To skip a file, type Enter. To retain the original path name, type . (period). This option is valid only with the-ioption.-RID — Reassigns ownership and group information for each file to a valid user ID. This option is valid only for the root user.-s— Swap bytes within each half word. Note: The-sand the-Sflags are basically for byte sequencing.-S— Swap half words within each word. Note: The-sand the-Sflags are basically for byte sequencing.-t— Creates a table of contents. This operation does not create any files. The-tflag and the-Vflag are mutually exclusive.-T— Truncates long file names to 14 characters. This option is valid only with the-ioption.-u— Copies unconditionally (normally, an older file will not replace a newer file with the same name).-v— This is the verbose option that causes a list of file names to be printed. When used with the-toption, the table of contents looks like the output of an ls -l command.-V— This is a special verbose option that allows to print a dot for each file read or written. Useful to assure the user that cpio is working without printing out all file names. Note that the-Vand-voptions are mutually exclusive and whichever occurs earlier in the command line will be processed accordingly ignoring the other.-6— Processes a UNIX System Sixth Edition archive format file. This option is mutually exclusive with the-cand-Hoptions.
매개변수
| 매개변수 | 설명 |
|---|---|
| Directory | 디렉터리. |
| Patterns | ksh의 패턴 하나 이상. 기본은 *(모든 파일). |
영어 원문
- Directory — Specifies the directory.
- Patterns — Specifies one or more patterns (as described in the ksh command) to be used with the command. The default for the Patterns parameter is an
*(asterisk), selecting all the files in the input.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 성공 |
| 0보다 큼 | 오류 |
영어 원문
0 The command completed successfully.
0 An error occurred.
예제
| 명령 | 하는 일 |
|---|---|
find . | /usr/sysv/bin/cpio -oc >/dev/rmt0 |
현재 디렉터리의 모든 파일을 테이프에 복사. -c로 다른 머신과 호환. find 대신 ls, cat, echo로 이름 목록을 줘도 되고 보통 파일로 보내도 됨 |
/usr/sysv/bin/cpio -icdI arfile |
아카이브 arfile의 모든 파일을 꺼내고 필요한 디렉터리를 만듦 |
/usr/sysv/bin/cpio -icd < arfile |
위와 같되 표준 입력으로 읽음(-I가 없을 때만) |
/usr/sysv/bin/cpio -icduI arfile |
arfile의 모든 파일을 무조건 꺼냄 |
/usr/sysv/bin/cpio -ickudI arfile |
헤더가 손상된 파일은 건너뛰고 꺼냄 |
ls | /usr/sysv/bin/cpio -oca > arfile |
아카이브를 만들며 원본의 접근 시각을 되돌림 |
cat ar | /usr/sysv/bin/cpio -ickud "a*" |
아카이브 ar에서 a로 시작하는 파일만 꺼냄 |
cat ar | /usr/sysv/bin/cpio -itv |
보관한 파일 목록(ls -l처럼) |
find . -print | /usr/sysv/bin/cpio -pd /home/user1/newdir |
현재 디렉터리 트리를 새 경로로 복사 |
find . -name "*.o" -print | /usr/sysv/bin/cpio -pdlmv /home/user1/newdir |
.o 파일만 수정 시각과 ACL을 유지하며 복사 |
ls d* | /usr/sysv/bin/cpio -oAO /tmp/ar |
d로 시작하는 파일을 아카이브 /tmp/ar에 덧붙임 |
cat ar | /usr/sysv/bin/cpio -i -E Efile |
파일 Efile에 적힌 파일만 꺼냄(아카이브에 있을 때) |
ls d* | /usr/sysv/bin/cpio -pdl /home/user2/newdir |
d로 시작하는 파일을 새 디렉터리에 하드 링크. 파일 시스템이 다르면 하드 링크할 수 없음 |
영어 원문
- To copy all the files in the current directory onto tape device /dev/rmt0, enter:
find . | /usr/sysv/bin/cpio -oc >/dev/rmt0
The -c option ensures that the file is made portable to other machines. Instead of find you can also use ls, cat, echo and so on to pipe a list of names to cpio. The output could also be redirected to a regular cpio file instead of a device.
- To extract an cpio archive file named "arfile" created by cpio command use the following:
/usr/sysv/bin/cpio -icdI arfile
Here all the files are extracted from the cpio archive and the -d option ensures that the required directory paths are created as when required.
- A cpio archive file can also be extracted as follows:
/usr/sysv/bin/cpio -icd < arfile
The -d option ensures that all the required directories are created under the current directory. The standard input can be used only if -I flag is not specified.
- To extract unconditionally all the files in "arfile" use the following:
/usr/sysv/bin/cpio -icduI arfile
- To skip any files which corrupted headers, cpio can be used as follows:
/usr/sysv/bin/cpio -ickudI arfile
- If the access time of the files archived needs to be reset when cpio is used to create an archive, use cpio in the following way:
ls | /usr/sysv/bin/cpio -oca > arfile
- To extract only the files matching the pattern "
a*" from the archive "ar", use the following:
cat ar | /usr/sysv/bin/cpio -ickud "a*"
This command extracts all the files starting with letter "a".
- To display the list of files archived, use cpio in the following way:
cat ar | /usr/sysv/bin/cpio -itv
The verbose option (-v) ensures that the list given by -t option is listed in a very similar way as ls -l command.
- The cpio -p command can be used to copy a directory tree to a new path, as follows:
find . -print | /usr/sysv/bin/cpio -pd /home/user1/newdir
The entire directory tree from current directory is copied to /home/user1/newdir. The -d option ensures that directories are created as necessary.
- To retain the modification time and access control list while copying the directory tree, use the cpio command as follows:
find . -name "*.o" -print | /usr/sysv/bin/cpio -pdlmv /home/user1/newdir
In this example only the .o files under the directory tree are copied to /home/user1/newdir.
- To append a list of files to a cpio archive matching a particular pattern, invoke a command similar to the following:
ls d* | /usr/sysv/bin/cpio -oAO /tmp/ar
In this example, all files starting with "d" in the current directory will be appended to the cpio archive.
- To extract only a list of files listed inside a regular file from an cpio archive, use the following command:
cat ar | /usr/sysv/bin/cpio -i -E Efile
In this example, cpio extracts only those files that are listed in the regular file "Efile", provided the specified file name exists in the archive.
- To hard link all the files instead of copying them, invoke a command similar to the following:
ls d* | /usr/sysv/bin/cpio -pdl /home/user2/newdir
In this example, the -l flag ensures all the file names starting with the character "d" are hard linked to the /home/user2/newdir, the directory specified. Hard linking across file systems is not allowed, thus the -l option cannot be used when the destination directory is in any other filesystem.
파일
| 파일 | 설명 |
|---|---|
/usr/sysv/bin/cpio |
System V cpio 명령 |
영어 원문
- /usr/sysv/bin/cpio — Contains the System V cpio command.
Related reference:
- cpio Command
Related information:
- find command
- ln command
- ls command
- tar command
리눅스(GNU)와 다른 점
리눅스의 GNU cpio도 -o, -i, -p와 -d, -m, -v, -t, -u를 같은 뜻으로 쓰지만, 옵션은 -idmv처럼 대시를 붙입니다. 기본 형식은 bin이고 다른 시스템과 주고받을 때는 -H newc(또는 crc, ustar)를 씁니다. 리눅스에서 cpio는 initramfs(-H newc)와 RPM 내용(rpm2cpio 패키지 | cpio -idmv)을 다룰 때 자주 씁니다.