cp 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-cp
핵심 정리
- 파일을 다른 파일로, 파일 여러 개를 디렉터리로, 디렉터리를 디렉터리로(
-r·-R) 복사합니다. - 대상 파일이 있으면 내용만 덮어쓰고 모드·소유자·그룹은 그대로 둡니다. 없으면 원본과 같은 모드로 새로 만들고, 소유자와 그룹은 복사한 사용자가 됩니다.
-p는 수정·접근 시각, 사용자·그룹 ID, 권한 비트를 그대로 옮기고 ACL도 유지합니다.-U는 확장 속성(EA)과 ACL을 옮깁니다.- 디렉터리 복사에는
-R을 권합니다.-R은 FIFO와 장치 파일을 새로 만들고,-r은 특수 파일을 일반 파일처럼 복사합니다. -i는 덮어쓰기 전에 묻고,-f는 쓰기로 열 수 없는 대상 파일을 먼저 지웁니다.-h는 심볼릭 링크를 따라가지 않고 링크 자체를 복사합니다.- 6.1에서
-e(암호화해서 저장),-d(평문으로 저장)가 생겼습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 암호화 파일 시스템용 -d, -e와 암호화 상태 표가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1 |
| 파일 | /usr/bin/cp |
| 관련 명령어 | cpio, ln, mv |
목적
파일을 복사합니다.
영어 원문
Copies files.
구문
파일을 다른 파일로 복사할 때:
cp [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -f ] [ -h ] [ -i ] [ -p ] [ -I ] [ -U ] [ -- ]
SourceFile TargetFile
파일을 디렉터리로 복사할 때:
cp [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -f ] [ -h ] [ -i ] [ -p ] [ [ -r | -R ] [ -H | -L | -P ] ]
[ -I ] [ -U ] [ -- ] SourceFile ... TargetDirectory
디렉터리를 디렉터리로 복사할 때:
cp [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -f ] [ -h ] [ -i ] [ -p ] { -r | -R } [ -H | -L | -P ]
[ -I ] [ -U ] [ -- ] SourceDirectory ... TargetDirectory
-d와 -e는 6.1 구문에만 있습니다. 원문 구문에는 마지막 플래그가 -(하이픈 하나)로 인쇄돼 있지만 플래그 표의 설명대로 --로 적었습니다.
설명
cp 명령은 SourceFile 매개변수로 지정한 원본 파일을 TargetFile 매개변수로 지정한 대상 파일로 복사합니다.
- 대상 파일이 있으면
cp는 내용을 덮어쓰지만, 그 파일의 모드, 소유자, 그룹은 바꾸지 않습니다. - SourceFile의 마지막 접근 시각과 TargetFile의 마지막 수정 시각은 복사한 시각이 됩니다.
- TargetFile이 없으면 원본 파일과 모드가 같은 새 파일을 만듭니다. 다만 슈퍼유저가 한 것이 아니면 스티키 비트는 켜지 않습니다. 새 파일의 소유자와 그룹은 복사한 사용자의 것입니다.
- TargetFile이 다른 파일에 대한 링크면, 링크가 가리키는 대상에 원본 내용을 덮어쓰고 TargetFile의 링크는 그대로 남습니다.
cp 명령은 SourceFile 매개변수로 지정한 파일들(또는 SourceDirectory 매개변수로 지정한 디렉터리들)을 TargetDirectory 매개변수로 지정한 디렉터리로 복사할 수도 있습니다.
참고: 원본 중 하나가 디렉터리면 -r이나 -R 플래그를 지정해야 합니다.
복사하는 동안 cp가 디렉터리를 만들면, 새 디렉터리의 모드는 대응하는 원본 디렉터리와 같습니다.
특수 장치 파일도 복사할 수 있습니다. 이때는 -R 플래그를 권합니다. -R을 지정하면 새 경로 이름 아래에 특수 파일을 다시 만듭니다. -r을 지정하면 특수 파일을 일반 파일로 복사하려고 합니다.
영어 원문
The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the TargetFile parameter. If the target file exists, cp overwrites the contents, but the mode, owner, and group associated with it are not changed. The last access time of the SourceFile and the last modification time of the TargetFile are set to the time the copy was done. If the TargetFile does not exist, cp creates a new file named TargetFile that has the same mode as the source file except that the sticky bit is not set unless it was done by a superuser; the owner and group of the TargetFile is that of the user. When the TargetFile is a link to another file, cp overwrites the destination link with the content of the source file; the links from the TargetFile remains. Also, the cp command can copy the source files specified by the SourceFile parameter (or directories named by the SourceDirectory parameter) to the directory specified by the TargetDirectory parameter.
Note: If one of the source parameters is a directory, you need to specify one of the -r or -R flags.
If any directories are created by the cp command during the copying process, the newly created directory will have the same mode as the corresponding source directory.
You can also copy special device files. The preferred option for accomplishing this is the -R flag. Specifying -R causes the special files to be re-created under the new path name. Specifying the -r flag causes the cp command to attempt to copy the special file to a regular file.
플래그
| 플래그 | 설명 |
|---|---|
-d |
원본 파일을 대상에 복호화된(평문) 형식으로 저장합니다. 6.1부터 |
-e |
대상 파일 시스템이 암호화 파일 시스템(EFS)이면 원본 파일을 암호화된 형식으로 저장합니다. 6.1부터 |
-E |
다음 인수 중 하나가 필요합니다. -E를 생략하면 warn이 기본입니다. force는 파일의 고정 익스텐트 크기나 공간 예약을 유지할 수 없으면 그 파일의 복사를 실패시킵니다. ignore는 익스텐트 속성을 유지하다 나는 오류를 무시합니다. warn은 공간 예약이나 고정 익스텐트 크기를 유지할 수 없으면 경고를 냅니다. |
-f |
대상 파일을 쓰기로 열 수 없으면 지웁니다. 지우는 일이 복사보다 먼저 일어납니다. |
-h |
심볼릭 링크를 복사합니다. 기본은 심볼릭 링크를 따라가 링크가 가리키는 파일을 복사합니다. |
-H |
SourceFile 피연산자로 지정한 심볼릭 링크는 그 링크가 가리키는 파일의 종류와 내용에 따라 처리합니다. |
-i |
덮어쓸 파일의 이름을 보여 주며 묻습니다. TargetDirectory나 TargetFile에 SourceFile·SourceDirectory와 이름이 같은 파일이 있을 때 일어납니다. y(또는 로캘에서 같은 뜻의 글자)를 입력하면 계속하고, 다른 답이면 덮어쓰지 않습니다. |
-I |
ACL 변환 중의 경고 메시지를 숨깁니다. |
-L |
SourceFile 피연산자로 지정한 심볼릭 링크와, 파일 계층을 탐색하다 만나는 심볼릭 링크를 모두 그 링크가 가리키는 파일의 종류와 내용에 따라 처리합니다. |
-p |
원본의 다음 특성을 대상에 그대로 옮깁니다(아래 설명). |
-P |
SourceFile 피연산자로 지정한 심볼릭 링크와, 파일 계층을 탐색하다 만나는 심볼릭 링크를 링크 자체로 처리합니다. |
-r |
SourceFile이나 SourceDirectory 아래의 파일 계층을 복사합니다(재귀 복사). 특수 파일을 일반 파일과 같은 방식으로 처리합니다. |
-R |
SourceFile이나 SourceDirectory 디렉터리의 일반 파일과 디렉터리 계층을 TargetDirectory로 복사합니다. FIFO, 블록·문자 장치 파일 같은 특수 파일은 복사하지 않고 새로 만듭니다. -h를 지정하지 않으면 심볼릭 링크를 따라갑니다. -r보다 -R을 권합니다. |
-U |
SourceFile의 확장 속성(EA)과 접근 제어 목록(ACL)을 TargetFile로 복사합니다. 대상 파일 시스템이 EA를 지원하지 않으면 무시합니다. 원본 ACL 형식을 대상 파일 시스템이 지원하지 않으면 지원하는 호환 형식으로 변환합니다. |
-- |
이 뒤의 매개변수를 파일 이름으로 해석합니다. -(빼기)로 시작하는 파일 이름을 지정할 수 있습니다. |
-p가 옮기는 것
- 마지막 데이터 수정 시각과 마지막 접근 시각. 실패하면 표준 오류에 진단 메시지를 씁니다. 나노초 자리는 옮기지 않습니다.
- 사용자 ID와 그룹 ID. 실패하면 표준 오류에 진단 메시지를 쓸 수 있습니다.
- 파일 권한 비트와
S_ISUID·S_ISGID비트. 실패하면 표준 오류에 진단 메시지를 씁니다. 사용자 ID나 그룹 ID를 옮기지 못하면S_ISUID와S_ISGID비트를 지웁니다.
소유자 ID, 그룹 ID, 권한 모드, 수정·접근 시각을 유지하려면 알맞은 접근 권한이 있어야 합니다(슈퍼유저이거나 대상 파일과 소유자 ID가 같아야 합니다). 이 특성을 유지하지 못해도 대상 파일을 지우지는 않습니다.
SourceFile의 ACL은 대상 파일 시스템이 같은 형식을 지원하면 유지합니다. 원본 파일에 NFS4 ACL이 있는데 대상 파일 시스템이 NFS4 ACL을 지원하지 않으면 AIXC 형식으로 변환하고, 변환에 성공하면 표준 오류에 경고 메시지를 씁니다.
6.1에서 더해진 내용: 원본 파일이 암호화돼 있고 -p를 지정하면 EFS 정보를 유지합니다. 보통 -e나 -d가 -p보다 우선합니다. -e로 평문 파일을 암호화 형식으로 바꾸게 하면, -p를 함께 줘도 마지막 수정·접근 시각 같은 속성은 유지하지 않습니다. 암호화 상태가 바뀌지 않는 한 -p는 파일 속성과 EFS 정보를 유지합니다.
-R과 -H·-L·-P
-H, -L, -P 중 아무것도 지정하지 않으면 어느 것을 기본으로 쓸지는 정해져 있지 않습니다.
-H를 지정하면 SourceFile 피연산자로 지정한 심볼릭 링크는 링크가 가리키는 파일의 종류와 내용에 따라 처리합니다.-L을 지정하면 SourceFile 피연산자로 지정한 링크와 탐색 중에 만나는 링크를 모두 가리키는 파일에 따라 처리합니다.-P를 지정하면 SourceFile 피연산자로 지정한 링크와 탐색 중에 만나는 링크를 링크 자체로 복사하고, 어떤 링크도 따라가지 않습니다.
대상 파일의 암호화 상태 (6.1)
| 지정한 플래그 | 원본 파일 | 대상 파일 시스템 | 결과 |
|---|---|---|---|
-e |
EFS 아님 | EFS 아님 | 오류 |
-e |
EFS 아님 | EFS | 암호화된 파일 |
-e |
EFS | EFS | 암호화된 파일 |
-e |
EFS | EFS 아님 | 오류 |
-d |
EFS 아님 | EFS 아님 | 평문 파일 |
-d |
EFS 아님 | EFS | 평문 파일 |
-d |
EFS | EFS 아님 | 평문 파일 |
-d |
EFS | EFS | 평문 파일 |
| 없음 | EFS 아님 | EFS 아님 | 평문 파일 |
| 없음 | EFS 아님 | EFS | 대상 디렉터리에 EFS 상속이 켜져 있으면 암호화된 파일, 아니면 평문 파일 |
| 없음 | EFS | EFS | 암호화된 파일 |
| 없음 | EFS | EFS 아님 | 오류 |
참고: -f를 지정하지 않으면 암호화된 파일을 평문 파일로, 또는 그 반대로 덮어쓸 수 없습니다. 대상의 암호화 상태는 -e·-d 플래그가 정하고, -f와 함께 -e·-d를 지정하지 않으면 암호화 상속이, 상속도 꺼져 있으면 원본 파일의 암호화 상태가 정합니다.
영어 원문
-d— Specifies that the source file is stored in decrypted (clear-text) format on target.-e— Specifies that the source file is stored in encrypted form, if the target file system is an Encrypted File System (EFS).-E— The-Eoption requires one of the following arguments. If you omit the-Eoption, warn is the default behavior. force Fails the cp operation on a file if the fixed extent size or space reservation of the file 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.-f— Specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.-h— Forces the cp command to copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.-H— Take actions based on the type and contents of the file referenced by any symbolic link specified as a SourceFile operand.-i— Prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enteryor the locale's equivalent ofy, the cp command continues. Any other answer prevents the cp command from overwriting the file.-I— Suppresses the warning message during ACL conversion.-L— Take actions based on the type and contents of the file referenced by any symbolic link specified as a SourceFile operand or any symbolic links encountered during traversal of a file hierarchy.-p— Duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory: • The time of the last data modification and the time of the last access. If this duplication fails for any reason, the cp command will write a diagnostic message to standard error. The nanoseconds field of the SourceFile/SourceDirectory is not duplicated for last modification time or last access time. • The user ID and group ID. If this duplication fails for any reason, the cp command may write a diagnostic message to standard error. • The file permission bits and theS_ISUIDandS_ISGIDbits. If this duplication fails for any reason, the cp command will write a diagnostic message to standard error. If the user ID or group ID cannot be duplicated, the file permission bitsS_ISUIDandS_ISGIDare cleared. In order to preserve the owner ID and group ID, permission modes, modification and access times, user must have the appropriate file access permissions (user should be a superuser or have the same owner ID as the destination file) The target file will not be deleted if these characteristics cannot be preserved. Access control lists (ACLs) associated with the SourceFile are preserved if the target filesystem supports the same. If the source file contains NFS4 ACL and the target filesystem does not support NFS4 ACL, the NFS4 ACL is converted to AIXC. When ACL conversion succeeds, a warning message is printed out the stderr. If the source file is encrypted and the-pflag is specified, the cp command preserves the EFS information. Generally, the-eor-dflag takes precedence over the –p flag. If a user requests to convert a clear-text file to an encrypted format using the-eflag, then even if the user specifies the-pflag, the copy does not preserve attributes like the time of the last data modification, the time of the last access and so on. As long as the encryption or decryption status remains the same, the-pflag preserves the file attributes and EFS information.-P— Take actions on any symbolic link specified as a SourceFile operand or any symbolic link encountered during traversal of a file hierarchy.-r— Copies file hierarchies under the file or directory specified by the SourceFile or SourceDirectory parameter (recursive copy). The-rflag processes special files in the same manner as regular files.-R— Copies file hierarchies under the regular files and directories from the directory specified by the SourceFile or SourceDirectory parameter to the directory specified by the TargetDirectory parameter. Special file types, such as first-in, first-out (FIFO) files and block and character device files, are re-created instead of copied. Symbolic links are followed unless the-hflag is specified. (The-Rflag is preferred to the-rflag.) If none of the-H,-L, or-Poptions were specified, it is unspecified which of those options will be used as the default. Consider the following: • If the-Hoption was specified, the cp command will take action based on the type and contents of the file referenced by any symbolic link specified as a SourceFile operand. • If the-Loption was specified, the cp command will take action based on the type and contents of the file referenced by any symbolic link specified as a SourceFile operand or any symbolic links encountered during traversal of a file hierarchy. • If the-Poption was specified, the cp command will copy any symbolic link specified as a SourceFile operand and any symbolic links encountered during traversal of a file hierarchy and will not follow any symbolic links.-U— Copies Extended Attributes (EA), Access Control Lists ( ACL ) in the SourceFile to the TargetFile. If the EA is not supported on the target filesystem then it is ignored. If the source ACL type is not supported on the target filesystem then it is converted to the compatible ACL type supported by the target filesystem.--— Indicates that parameters following the--(dash, dash) flag are to be interpreted as file names. This null flag allows the specification of file names that start with a-(minus sign).
The following table shows the encryption or decryption status of the target file under different conditions:
| Explicit flag for the cp command | Source file | Target file system | Result |
|---|---|---|---|
-e (encrypted) |
Non-EFS | Non-EFS | Error |
-e |
Non-EFS | EFS | Encrypted file |
-e |
EFS | EFS | Encrypted file |
-e |
EFS | Non-EFS | Error |
-d (decrypted) |
Non-EFS | Non-EFS | Clear-text file |
-d |
Non-EFS | EFS | Clear-text file |
-d |
EFS | Non-EFS | Clear-text file |
-d |
EFS | EFS | Clear-text file |
| No explicit flag | Non-EFS | Non-EFS | Clear-text file |
| No explicit flag | Non-EFS | EFS | If the target directory is EFS inheritance enabled, the target file is an encrypted file. Otherwise the target file is a clear-text file. |
| No explicit flag | EFS | EFS | Encrypted file |
| No explicit flag | EFS | Non-EFS | Error |
Note: It is not permitted to overwrite an encrypted file with a plain-text file and vice versa unless you specify the -f flag. The encryption status of the target depends on the -e or -d flag, the encryption inheritance if you do not specify the -e or -d flag with the -f flag, and the encryption status of the source file if the encryption inheritance is not active.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 모든 파일을 잘 복사했습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — All files were copied successfully.
>0— An error occurred.
예제
- 현재 디렉터리에서 파일의 사본을 만듭니다.
prog.c를prog.bak로 복사합니다.prog.bak가 없으면 새로 만들고, 있으면prog.c의 사본으로 바꿉니다.
cp prog.c prog.bak
- 현재 디렉터리의 파일을 다른 디렉터리로 복사합니다.
jones파일이/home/nick/clients/jones로 복사됩니다.
cp jones /home/nick/clients
- 원본의 수정 날짜·시각과 접근 제어 목록을 유지하며 새 파일로 복사합니다.
smith.jr는 현재 날짜·시각 대신smith와 같은 날짜·시각을 갖고,smith의 접근 제어 보호도 물려받습니다.
cp -p smith smith.jr
- 디렉터리 안의 모든 파일을 새 디렉터리로 복사합니다.
clients디렉터리의 파일만customers디렉터리로 복사합니다.
cp /home/janet/clients/* /home/nick/customers
- 디렉터리를 그 안의 모든 파일과 하위 디렉터리까지 다른 디렉터리로 복사합니다.
clients디렉터리 전체가customers/clients로 복사됩니다. 디렉터리를 자기 자신 안으로 복사할 수는 없습니다.
cp -R /home/nick/clients /home/nick/customers
- 정해 둔 파일 몇 개를 다른 디렉터리로 복사합니다. 현재 디렉터리의
jones,lewis,smith가/home/nick/clients로 복사됩니다.
cp jones lewis smith /home/nick/clients
- 패턴 일치 문자로 파일을 복사합니다.
programs디렉터리에서 이름이.c로 끝나는 파일을 현재 디렉터리(마지막의.)로 복사합니다.c와 마지막 점 사이에 공백이 있어야 합니다.
cp programs/*.c .
- 원본의 ACL과 EA를 유지하며 새 파일로 복사합니다.
cp -U smith smith.jr
영어 원문
- To make a copy of a file in the current directory, enter:
cp prog.c prog.bak
This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- To copy a file in your current directory into another directory, enter:
cp jones /home/nick/clients
This copies the jones file to /home/nick/clients/jones.
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
cp -p smith smith.jr
This copies the smith file to the smith.jr file. Instead of creating the file with the current date and time stamp, the system gives the smith.jr file the same date and time as the smith file. The smith.jr file also inherits the smith file's access control protection.
- To copy all the files in a directory to a new directory, enter:
cp /home/janet/clients/* /home/nick/customers
This copies only the files in the clients directory to the customers directory.
- To copy a directory, including all its files and subdirectories, to another directory, enter:
cp -R /home/nick/clients /home/nick/customers
Note: A directory cannot be copied into itself. This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- To copy a specific set of files to another directory, enter:
cp jones lewis smith /home/nick/clients
This copies the jones, lewis, and smith files in your current working directory to the /home/nick/clients directory.
- To use pattern-matching characters to copy files, enter:
cp programs/*.c .
This copies the files in the programs directory that end with .c to the current directory, signified by the single . (dot). You must type a space between the c and the final dot.
- To copy a file to a new file and preserve the ACL and EA associated with the source file, enter:
cp -U smith smith.jr
파일
| 파일 | 설명 |
|---|---|
/usr/bin/cp |
cp 명령이 들어 있습니다. |
관련 명령어: cpio, ln, mv
영어 원문
/usr/bin/cp Contains the cp command.
Related reference:
- cpio Command
Related information:
- User accounts
- ln command
- mv command
- National Language Support Overview
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU cp |
|---|---|---|
-h |
심볼릭 링크를 링크 자체로 복사 | 없음(-P나 --no-dereference) |
-U |
확장 속성·ACL 복사 | 없음(--preserve=xattr) |
-e·-d |
EFS 암호화·평문으로 저장(6.1) | 없음 |
-E |
VxFS 익스텐트 속성 처리 | 없음 |
-r |
특수 파일을 일반 파일처럼 복사 | -R과 같음 |
AIX 5.3·6.1 문서에는 -a(보관 모드), -u(새것만), -v(진행 표시), --backup 같은 GNU 플래그가 없습니다.