mv 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-mv
핵심 정리
- 파일이나 디렉터리를 다른 디렉터리로 옮기거나 이름을 바꿉니다.
- 같은 파일 시스템 안이든 다른 파일 시스템으로든, 대상에 복사한 뒤 원본을 지웁니다. 수정·접근 시각, 사용자·그룹 ID, 모드, 확장 속성, ACL을 그대로 유지합니다.
-i를 주지 않으면 기존 파일을 말없이 덮어쓸 수 있습니다.-i는 덮어쓰기 전에 묻고,-f는 묻지 않습니다. 둘을 함께 쓰면 마지막 것이 이깁니다.- 쓰기 권한이 없는 파일을 덮어쓰게 되면, 표준 입력이 터미널일 때 권한 코드를 보여 주고
y답을 기다립니다. - NFS 버전 4 referral로 내보낸 객체는 옮기지 않습니다.
- 6.1에서
-e(암호화해서 저장),-d(평문으로 저장)가 생겼습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 암호화 파일 시스템용 -d, -e와 암호화 상태 표가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 3, 6.1 Volume 3 |
| 파일 | /usr/bin/mv |
| 관련 명령어 | ln, cp, chmod, rename |
목적
파일을 옮깁니다.
영어 원문
Moves files.
구문
파일을 옮기거나 이름을 바꿀 때:
mv [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -i | -f ] [ -I ] SourceFile ... TargetFile
디렉터리를 옮기거나 이름을 바꿀 때:
mv [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -i | -f ] [ -I ] SourceDirectory ... TargetDirectory
원래 이름을 그대로 두고 파일이나 디렉터리를 디렉터리로 옮길 때:
mv [ -d ] [ -e ] [ -E {force|ignore|warn} ] [ -i | -f ] [ -I ] SourceFile/SourceDirectory TargetDirectory
-d와 -e는 6.1 구문에만 있습니다.
설명
주의: -i 플래그를 지정하지 않으면 mv 명령은 기존 파일을 여럿 덮어쓸 수 있습니다. -i는 파일을 덮어쓰기 전에 확인을 받습니다. -f와 -i를 함께 지정하면 마지막에 지정한 것이 우선합니다.
mv 명령은 파일과 디렉터리를 한 디렉터리에서 다른 디렉터리로 옮기거나, 파일이나 디렉터리의 이름을 바꿉니다.
- 파일이나 디렉터리를 새 디렉터리로 옮기면 기본 파일 이름은 그대로입니다.
- 파일을 옮겨도 다른 파일로의 링크는 그대로 남습니다. 다만 다른 파일 시스템으로 옮길 때는 예외입니다.
- 디렉터리를 이미 있는 디렉터리로 옮기면, 그 디렉터리와 내용이 기존 디렉터리 아래에 더해집니다.
mv 명령으로 이름을 바꿀 때 TargetDirectory 매개변수에는 새 파일 이름이나 새 디렉터리 경로를 지정합니다.
옮기면서 쓰기 권한이 없는 기존 파일을 덮어쓰게 되고 표준 입력이 워크스테이션(터미널)이면, mv는 파일 권한 코드를 표시하고 표준 입력에서 한 줄을 읽습니다. 그 줄이 y(또는 로캘에서 같은 뜻의 글자)로 시작하면 파일을 옮기고, 아니면 그 파일은 그대로 두고 다음 파일로 넘어갑니다. TargetFile에 ACL이 있으면 표시한 권한 코드가 실제 접근 권한을 다 나타내지 못할 수 있습니다.
SourceFile의 부모 디렉터리가 쓰기 가능하고 스티키 비트가 켜져 있으면, 다음 조건 중 하나 이상을 만족해야 합니다.
- 사용자가 그 파일을 소유합니다.
- 사용자가 그 디렉터리를 소유합니다.
- 사용자가 특권 사용자입니다.
- 사용자가 그 파일에 쓸 수 있습니다.
이 경고 메시지와 입력 요청은 -f 옵션으로 건너뛸 수 있습니다.
mv 명령은 같은 파일 시스템 안에서도, 파일 시스템 사이에서도 파일을 옮길 수 있습니다. 어느 경우든 파일을 대상에 복사한 뒤 원본을 지웁니다. 새 파일에는 원본의 최근 데이터 수정 시각, 최근 접근 시각, 사용자 ID, 그룹 ID, 파일 모드, 확장 속성, ACL을 그대로 유지합니다. 심볼릭 링크는 링크 자체의 소유자와 그룹만 유지합니다.
소유자와 그룹 ID를 유지하지 못하면 대상에서 S_ISUID와 S_ISGID 비트를 지웁니다. 이 비트를 지우지 못하면 표준 오류에 진단 메시지를 쓰지만 종료 코드에는 영향이 없습니다.
mv 명령이 도중에 끝나면 원본 파일이나 대상 경로가 바뀐 채로 남을 수 있습니다.
참고: mv 명령은 플래그의 끝을 나타내는 구분자로 --(대시 두 개) 매개변수를 지원합니다.
mv 명령은 NFS 버전 4 referral로 내보낸 객체를 옮기지 않습니다. referral 객체는 사용 중으로 표시되며, 내보내기를 해제할 때까지 그대로입니다.
영어 원문
Attention: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm before it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.
The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system. When you move a directory into an existing directory, the directory and its contents are added under the existing directory.
When you use the mv command to rename a file or directory, the TargetDirectory parameter can specify either a new file name or a new directory path name.
If moving the file would overwrite an existing file that does not have write-permission set and if standard input is a workstation, the mv command displays the file-permission code and reads a line from standard input. If that line begins with a y or the locale's equivalent of a y, the mv command moves the file. If the response is anything other than a y, the mv command does nothing to that file and continues with the next specified file. The file-permission code displayed may not fully represent the access permission if the TargetFile is associated with an ACL. When the parent directory of the SourceFile is writable and has the sticky bit set, one or more of the following conditions are true:
The user must own the file.
The user must own the directory
The user must be a privileged user.
The file must be writable by the user.
This warning message and prompt for input can be overridden by using the -f option.
You can use the mv command to move files within the same file system or between file systems. Whether you are working in one file system or across file systems, the mv command copies the file to the target and deletes the original file. The mv command preserves in the new file the time of the most recent data modification, the time of the most recent access, the user ID, the group ID, the file mode, the extended attributes, and ACLs of the original file. For symbolic links, the mv command preserves only the owner and group of the link itself.
If it is unable to preserve the owner and group ID, the mv command clears S_ISUID and S_ISGID bits in the target. The mv command prints a diagnostic message to stderr if it is unable to clear these bits, though the exit code is not affected.
The mv command modifies either the source file or the destination path if the command is prematurely terminated.
Note: The mv command supports the — (dash, dash) parameter as a delimiter that indicates the end of the flags.
The mv command will not move an object if the object is exported as an NFS version 4 referral. The referral object is marked as busy and remains so until it is unexported."
플래그
| 플래그 | 설명 |
|---|---|
-d |
원본 파일을 대상에 복호화된(평문) 형식으로 저장합니다. 6.1부터 |
-e |
대상 파일 시스템이 암호화 파일 시스템(EFS)이면 원본 파일을 암호화된 형식으로 저장합니다. 6.1부터 |
-E |
다음 인수 중 하나가 필요합니다. -E를 생략하면 warn이 기본입니다. force는 파일의 고정 익스텐트 크기나 공간 예약을 유지할 수 없으면 그 파일의 이동을 실패시킵니다. ignore는 익스텐트 속성을 유지하다 나는 오류를 무시합니다. warn은 공간 예약이나 고정 익스텐트 크기를 유지할 수 없으면 경고를 냅니다. |
-f |
기존 파일을 덮어쓰기 전에 묻지 않습니다. |
-i |
이미 있는 경로로 파일이나 디렉터리를 옮기기 전에, 파일 이름 뒤에 물음표를 붙여 보여 주며 묻습니다. y(또는 로캘에서 같은 뜻의 글자)로 시작하는 줄로 답하면 계속하고, 다른 답이면 옮기지 않습니다. |
-I |
ACL 변환 중의 경고 메시지를 숨깁니다. |
대상 파일의 암호화 상태 (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를 지정하지 않으면 암호화 상속이, 상속도 꺼져 있으면 원본 파일의 암호화 상태가 정합니다.
영어 원문
Attention: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm before it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.
-d— The source file is stored in decrypted (clear-text) format on target.-e— 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 mv 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— Does not prompt you before overwriting an existing file.-i— Prompts you before moving a file or directory to an existing path name by displaying the name of the file followed by a question mark. If you answer with a line starting withyor the locale's equivalent of ay, the move continues. Any other reply prevents the move from occurring.-I— Suppresses the warning message during ACL conversion.
The following table shows the encryption or decryption status of the target file under different conditions:
| Explicit flag for the mv 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 file system is EFS activated, the target file is an encrypted file. Else, 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.
예제
- 파일 이름을 바꿉니다.
appendix를apndx.a로 바꿉니다.apndx.a가 이미 있으면 그 내용이appendix의 내용으로 바뀝니다.
mv appendix apndx.a
- 디렉터리를 옮깁니다.
manual이 있으면book아래의 모든 파일과 디렉터리를manual로 옮기고, 없으면book디렉터리의 이름을manual로 바꿉니다.
mv book manual
- 파일을 다른 디렉터리로 옮기며 새 이름을 줍니다.
intro를manual/chap1로 옮깁니다. 현재 디렉터리에서intro라는 이름이 없어지고, 같은 파일이manual디렉터리에chap1으로 나타납니다.
mv intro manual/chap1
- 이름은 그대로 두고 파일을 다른 디렉터리로 옮깁니다.
chap3이manual/chap3으로 옮겨집니다.
mv chap3 manual
참고: 예제 1과 3은 파일 두 개를, 예제 2는 이미 있는 디렉터리 두 개를, 예제 4는 파일 하나와 디렉터리 하나를 지정합니다.
- 파일 여러 개를 다른 디렉터리로 옮깁니다.
chap4는/home/manual/chap4로,jim/chap5는/home/manual/chap5로 옮겨집니다.
mv chap4 jim/chap5 /home/manual
- 패턴 일치 문자와 함께 씁니다.
manual디렉터리의 모든 파일을 원래 이름 그대로 현재 디렉터리(.)로 옮기고,manual은 비게 됩니다. 별표와 마침표 사이에 공백이 있어야 합니다.
mv manual/* .
참고: 패턴 일치 문자는 이미 있는 파일의 이름으로만 펼쳐집니다. 예를 들어 manual/chap1 파일이 없으면 mv intro man*/chap1은 동작하지 않습니다.
영어 원문
- To rename a file, enter:
mv appendix apndx.a
This command renames appendix to apndx.a. If a file named apndx.a already exists, its old contents are replaced with those of appendix.
- To move a directory, enter:
mv book manual
This command moves all files and directories under book to the directory named manual, if manual exists. Otherwise, the directory book is renamed manual.
- To move a file to another directory and give it a new name, enter:
mv intro manual/chap1
This command moves intro to manual/chap1. The name intro is removed from the current directory, and the same file appears as chap1 in the directory manual.
- To move a file to another directory, keeping the same name, enter:
mv chap3 manual
This command moves chap3 to manual/chap3
Note: Examples 1 and 3 name two files, example 2 names two existing directories, and example 4 names a file and a directory.
- To move several files into another directory, enter:
mv chap4 jim/chap5 /home/manual
This command moves the chap4 file to the /home/manual/chap4 file directory and the jim/chap5 file to the /home/manual/chap5 file.
- To use the mv command with pattern-matching characters, enter:
mv manual/* . This command moves all files in the manual directory into the current directory . (period), retaining the names they had in manual. This move also empties manual. You must type a space between the asterisk and the period.
Note: Pattern-matching characters expand names of existing files only. For example, the command mv intro man*/chap1 does not work if the file manual/chap1 does not exist.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 모든 입력 파일을 잘 옮겼습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
- 0 — All input files were moved successfully.
>0— An error occurred.
파일
| 파일 | 설명 |
|---|---|
/usr/bin/mv |
mv 명령이 들어 있습니다. |
관련 명령어: ln, chmod, rename
영어 원문
- /usr/bin/mv — Contains the mv command.
Related reference:
- ln Command
Related information:
- chmod command
- rename command
- Input and output redirection
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU mv |
|---|---|---|
| 이동 방식 | 같은 파일 시스템 안에서도 "복사 후 원본 삭제"로 설명함 | 같은 파일 시스템이면 이름만 바꿈(rename) |
-E |
VxFS 익스텐트 속성 처리 | 없음 |
-e·-d |
EFS 암호화·평문으로 저장(6.1) | 없음 |
-I |
ACL 변환 경고 숨김 | 없음 |
AIX 5.3·6.1 문서에는 -n(덮어쓰지 않음), -u(새것만), -v(진행 표시), --backup 같은 GNU 플래그가 없습니다.