tar 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-tar
핵심 정리
- 파일을 아카이브(테이프나 파일)에 쓰거나 꺼냅니다. 동작 플래그
-c(만들기),-t(목록),-x(풀기),-r(끝에 덧붙이기),-u(새 것만 덧붙이기) 가운데 하나를 꼭 줍니다. - 자주 쓰는 형태:
tar -cvf /tmp/a.tar dir,tar -tvf /tmp/a.tar,tar -xvf /tmp/a.tar.-f가 없으면 기본 테이프/dev/rmt0를 씁니다. - AIX
tar에는 GNU tar의-z(gzip) 옵션이 없습니다. 압축은 파이프로 합니다:tar -cvf - dir | gzip > a.tar.gz,gunzip -c a.tar.gz | tar -xvf -. - 절대 경로로 만든 아카이브는 그 경로로 풀리므로 보통
cd한 뒤 상대 경로(.)로 만듭니다.-C 디렉터리로 위치를 바꿀 수 있습니다. -p는 권한을 그대로 풀고,-U는 확장 속성과 ACL을,-L 목록파일·-X 제외목록은 넣거나 뺄 파일 목록을 파일로 줍니다. 경로+이름은PATH_MAX까지만 보관합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 -Z(EFS 정보 보관), 파일 크기 제한이 없어지는 TL 안내가 더해지고, 5.3의 UID·GID 65,535 초과 경고가 빠짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 5, 6.1 Volume 5 |
| 파일 | /usr/bin/tar, /dev/rmt0, /tmp/tar* |
| 관련 명령어 | cpio, pax, dd, compress, gzip, backup, restore |
목적
아카이브를 다룹니다.
영어 원문
Manipulates archives.
구문
X/Open 형식:
tar { -c | -r | -t | -u | -x } [ -B ] [ -d ] [ -E ] [ -F ] [ -h ] [ -i ] [ -l ] [ -m ] [ -o ] [ -p ] [ -s ]
[ -U ] [ -v ] [ -w ] [ -Number ] [ -f Archive ] [ -b Blocks ] [ -S [ Feet ] [ Feet@Density ] [ Blocksb ] ]
[ -L InputList ] [ -X ExcludeList ] [ -N Blocks ] [ -R ] [ -D ] [ -C Directory ] [ -Z ] File | Directory ...
Berkeley 형식(대시 없이 플래그를 붙여 쓰고, 플래그 인수는 플래그 순서대로 뒤에 줌):
tar { c | r | t | u | x } [ b B d D E f F h i l L X m N o p R s S U v w Z [ 0-9 ] ] [ Blocks ] [ Archive ]
[ InputList ] [ ExcludeFile ] [ [ Feet ] | [ Feet@Density ] | [ Blocksb ] ] Directory | File ...
-Z는 6.1 구문에만 있습니다.
설명
참고:
- (6.1) ustar 헤더 형식은 AIX 6.1 TL9 이전에는 파일 크기를 8GB까지 허락하고, TL9 이후에는 제한이 없습니다(2^64 - 1). 5.3 문서는 8GB까지라고 적습니다.
tar는 희소(sparse) 파일의 희소성을 보존하지 않습니다. 원래 희소했던 파일도 풀면 파일 크기만큼 공간을 모두 차지합니다.
(5.3) 주의: 헤더 공간의 제한 때문에 65,535보다 큰 UID와 GID는 일부 시스템에서 풀 때 망가집니다. 소유권과 권한만 영향을 받고 데이터는 손상되지 않습니다. uname·gname 필드로 소유권을 확인하지 않는 시스템이나 보관한 시스템과 사용자·그룹 ID가 다른 시스템에서 생깁니다.
tar 명령은 아카이브 저장 매체에 파일을 쓰거나 꺼내 아카이브를 다룹니다. 다룰 파일은 File 매개변수로 주며, 디렉터리면 그 아래의 파일과 디렉터리도 모두 재귀로 다룹니다.
-f Archive로 다른 장치를 주지 않으면 기본 장치(보통 테이프)에서 아카이브를 찾습니다. USTAR 형식에서 100자보다 긴 경로 이름을 쓸 때는 경로가 접두 버퍼, /, 이름 버퍼로 나뉜다는 것을 기억합니다. 경로를 /로 두 부분에 나눌 수 없으면 보관하지 못합니다.
경로와 파일 이름의 길이는 시스템의 PATH_MAX까지만 지원하며, 그보다 길면 보관하지 않습니다.
아카이브에 쓸 때 tar는 임시 파일(/tmp/tar*)을 쓰고, 링크가 여럿인 파일의 표를 메모리에 둡니다. 임시 파일을 만들 수 없거나 링크 표를 둘 메모리가 모자라면 오류 메시지를 냅니다.
플래그는 필수 플래그와 선택 플래그 두 묶음입니다. 필수 플래그 -c, -r, -t, -u, -x가 tar의 동작을 정하며 적어도 하나를 꼭 줘야 합니다. 선택 플래그는 필요할 때만 줍니다.
참고:
- 저장 장치가 보통 파일이나 블록 특수 파일이면
-u와-r은 뒤로 감습니다. 원시 자기 테이프는 뒤로 감기를 지원하지 않아,-u·-r은 테이프를 되감고 열어 다시 읽습니다. - 블록 자기 테이프에서는 레코드가 한 블록이지만 원시 테이프에서는 보통 밀도가 그 반도 안 됩니다. 그래서 블록을 묶은 원시 테이프는 두 번 읽어야 하지만, 한 블록 레코드의 블록 테이프를 한 번 읽는 것보다 테이프 이동은 적습니다.
- 스트리밍 테이프는 테이프 끝에 정보를 덧붙일 수 없어
-u와-r을 쓸 수 없습니다. 쓰면tar: Update and Replace options not valid for a streaming tape drive.오류가 납니다. - 테이프 오류는 복구할 수 없습니다.
- IBM 9348 Magnetic Tape Unit Model 12에서는 기본 블록 크기를 바꿔 성능을 높일 수 있습니다:
chdev -l 장치이름 -a block_size=32k. 테이프 장치 사용은rmt특수 파일을 봅니다.
영어 원문
Note:
The ustar header format allows file sizes up to 8 GB in IBM AIX 6.1 with Technology Level 9, or earlier releases. In IBM AIX 6.1 with Technology Level 9, or later releases, this size is unlimited (2^64 -1).
The tar command 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.
The tar command manipulates archives by writing files to, or retrieving files from an archive storage medium. The files used by the tar command are represented by the File parameter. If the File parameter refers to a directory, then that directory and recursively all files and directories within it are referenced as well.
The tar command looks for archives on the default device (usually tape), unless you specify another device with the -f Archive flag. When specifying path names that are greater than 100 characters for the United States Tape Archiver (USTAR) format, remember that the path name is composed of a prefix buffer, a / (slash), and a name buffer.
The tar command supports the length of path+filename only till the system defined PATH_MAX limit. Any length of path+filename input greater than PATH_MAX limit is not archived
When writing to an archive, the tar command uses a temporary file (the /tmp/tar* file) and maintains in memory a table of files with several links. You receive an error message if the tar command cannot create the temporary file, or if there is not enough memory available to hold the link tables.
Two groups of flags exist for the tar command: the required flags and the optional flags. The required flags control the actions of the tar command and include the -c, -r, -t, -u, and -x flags. At least one required flag must be selected for the tar command to function. Having selected a required flag, you can select an optional flag but none are necessary to control the tar command.
Note:
When the storage device is an ordinary file or a block special file, the
-uand-rflags backspace. However, raw magnetic tape devices do not support backspacing. So when the storage device is a raw magnetic tape, the-uand-rflags rewind the tape, open it, and then read it again.Records are one block long on block magnetic tape, but they are typically less than half as dense on raw magnetic tape. As a result, although a blocked raw tape must be read twice, the total amount of tape motion is less than when reading one-block records from a block magnetic tape once.
The structure of a streaming tape device does not support the addition of information at the end of a tape. Consequently when the storage device is a streaming tape, the
-uand-rflags are not valid options. An attempt to use these flags results in the following error message:
tar: Update and Replace options not valid for a
streaming tape drive.
No recovery exists from tape errors.
The performance of the tar command to the IBM9348 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
For more information on using tape devices see the rmt special file.
플래그
플래그는 필수와 선택 두 묶음이며, 필수 플래그를 적어도 하나 줘야 합니다.
필수 플래그:
| 플래그 | 설명 |
|---|---|
-c |
새 아카이브를 만들고 File의 파일을 아카이브 처음부터 씁니다. |
-r |
File의 파일을 아카이브 끝에 씁니다. 테이프 장치는 끝에 덧붙일 수 없어 쓸 수 없습니다. |
-t |
아카이브에 있는 순서대로 파일을 나열합니다. 같은 파일이 여러 번 나올 수 있습니다. |
-u |
아카이브에 없거나 아카이브에 쓴 뒤 바뀐 파일만 아카이브 끝에 덧붙입니다. 테이프 장치에는 쓸 수 없습니다. |
-U |
확장 속성(ACL 포함)을 보관하고 풉니다. |
-x |
File의 파일을 아카이브에서 꺼냅니다. 디렉터리면 재귀로 꺼내고, File이 없으면 모두 꺼냅니다. 같은 파일이 여럿이면 마지막 것이 앞의 것을 덮어씁니다. 시스템에 없는 파일은 만듭니다. 권한이 있으면 테이프의 소유자·그룹 ID대로, 없으면 자기 ID로 풉니다. 마지막이 아닌 사본만 골라 꺼낼 수는 없습니다. |
선택 플래그:
| 플래그 | 설명 |
|---|---|
-B |
레코드당 20블록으로 입출력을 강제합니다. 블록이 유지되지 않는 통신 채널에서도 동작하게 합니다. |
-b Blocks |
레코드당 512바이트 블록 수. 기본이자 최댓값은 20입니다. 레코드 사이 간격 때문에 큰 블록으로 쓴 테이프에 더 많이 담깁니다. 읽을 때(-x, -t)는 블록 크기를 자동으로 알아내고, -u·-r은 기존 레코드 크기를 쓰며, Blocks는 -c로 새로 만들 때만 씁니다. 보통 파일에 쓸 때는 디스크 블록에 맞추면 공간을 아낍니다(예: 2048바이트 블록이면 -b4). |
-C Directory |
그 디렉터리로 chdir합니다. 공통 부모가 가깝지 않은 여러 디렉터리를 짧은 상대 경로로 보관할 수 있습니다(예: tar c -C /usr/include File1 File2 -C /etc File3 File4). 풀 때도 여러 번 쓸 수 있으며, 각 -C는 앞의 -C에 대한 상대 경로입니다. 아카이브에 /home/dir1/filename 같은 절대 경로가 있으면 앞의 /를 떼고 -C 디렉터리 아래로 풉니다. 다른 모든 플래그 뒤에 두며 파일 이름 목록 안에 둘 수 있습니다. |
-D |
디렉터리를 줬을 때 재귀 처리를 하지 않습니다. |
-d |
블록 파일, 문자 특수 파일, FIFO를 따로 항목으로 만듭니다. 보통은 보관하지 않으며, 이 플래그로 보관하면 -x로 빈 디렉터리와 특수 파일, FIFO를 되살릴 수 있습니다. 특수 파일은 누구나 보관할 수 있지만 꺼내는 것은 root만 됩니다(FIFO는 root가 아니어도 됨). |
-E |
새 아카이브나 기존 아카이브에 파일을 더할 때 긴 사용자·그룹 이름을 자르지 않습니다. |
-F |
보관하기 전에 파일 종류를 검사해 SCCS·RCS 파일, core, errs, a.out, .o로 끝나는 파일은 보관하지 않습니다. |
-f Archive |
읽거나 쓸 아카이브. 없으면 시스템 기본값 /dev/rmt0 형식을 씁니다. -면 표준 출력에 쓰거나 표준 입력에서 읽으며, 표준 출력에 쓸 때는 -c를 써야 합니다. |
-h |
심볼릭 링크를 따라가 보통 파일이나 디렉터리처럼 다룹니다. 기본은 따라가지 않습니다. |
-i |
헤더 체크섬 오류를 무시합니다. 없으면 체크섬이 맞지 않을 때 directory checksum error로 멈추고, 있으면 오류를 기록하고 올바른 헤더를 찾을 때까지 건너뜁니다. 여러 볼륨 아카이브의 뒤 볼륨부터 풀 때 씁니다. |
-L InputList |
보관하거나 꺼낼 파일과 디렉터리를 나열한 파일의 이름. |
-l |
링크 수가 1보다 큰데 그 링크가 함께 보관되지 않은 파일마다 오류 메시지를 표준 출력에 씁니다. |
-m |
꺼낸 시각을 수정 시각으로 씁니다. 기본은 파일의 수정 시각을 보존합니다. |
-N Blocks |
스트리밍 테이프에서 아주 큰 블록 묶음을 씁니다. 읽을 때는 이렇게 만든 긴 블록 크기를 자동으로 알아내지 못하며, -N이 없으면 자동으로 알 수 있는 최대 블록 크기는 20블록입니다. |
-o |
예전(AIX가 아닌) tar와 호환됩니다. 읽을 때 꺼낸 파일이 아카이브가 아닌 실행한 사용자의 UID·GID를 갖습니다(일반 사용자의 기본 동작). |
-p |
현재 umask를 무시하고 원래 모드로 풉니다. root에게는 setuid, setgid, sticky 비트도 되살립니다. |
-R |
디렉터리를 줬을 때 재귀로 처리합니다. -D와 함께면 무시합니다. |
-S Blocksb, -S Feet, -S Feet@Density |
볼륨당 512KB 블록 수(첫째 형식), 테이프 길이(피트, 기본 밀도로 계산), 길이와 밀도를 줍니다. 1피트는 넉넉히 11인치로 계산합니다. 여러 볼륨 테이프 아카이브에서 볼륨마다 몇 블록이 들어가는지 정할 때 씁니다. 1/4인치 테이프는 트랙 수를 고려해, 4트랙 600피트 8000bpi면 -S 2400@8000(600 × 4 = 2400)으로 줍니다. |
-s |
보통 링크를 만드는 데 실패하면 심볼릭 링크를 만들어 봅니다. |
-v |
처리하는 파일 이름을 나열합니다. -t와 함께면 크기, 수정 시각, UID, GID, 권한까지 보여 줍니다. |
-w |
할 동작과 파일 이름을 보여 주고 확인을 기다립니다. 긍정으로 답하면 하고, 아니면 건너뜁니다. |
-Number |
기본값 대신 /dev/rmtNumber를 씁니다. 예: -2는 -f/dev/rmt2와 같습니다. |
-X ExcludeList |
ExcludeList 파일에 있는 파일이나 디렉터리(한 줄에 하나)를 만들거나 꺼내거나 나열할 때 뺍니다. 여러 번 줄 수 있고 다른 모든 옵션보다 우선합니다. |
-Z |
암호화 파일 시스템(EFS) 파일·디렉터리의 EFS 정보를 보관합니다. 꺼낼 때는 기본으로 EFS 정보를 꺼냅니다. -t -v와 함께면 -Z로 보관한 암호화 파일 모드 뒤에 e, 다른 파일은 -가 보입니다. -Z로 만든 아카이브는 AIX 6.1 이후에서만 풀 수 있습니다. 6.1부터 |
영어 원문
Flags for the tar command are in two groups, the required and the optional. You must supply at least one required flag to control the tar command.
Table 2. Required Flags Required Flags Description -c Creates a new archive and writes the files specified by one or more File parameters to the beginning of the archive. -r Writes the files specified by one or more File parameters to the end of the archive. This flag is not valid for any tape devices because such devices do not support the addition of information at the end of a tape. -t Lists the files in the order in which they appear in the archive. Files can be listed more than once. -u Adds the files specified by one or more File parameters to the end of the archive only if the files are not in the archive already, or if they have been modified since being written to the archive. The -u flag is not valid for any tape devices because such devices do not support the addition of information at the end of a tape. -U Allows archival and extraction of Extended Attributes. The Extended Attributes include Access control list (ACL) also. -x Extracts the files specified by one or more File parameters from the archive. If the File parameter refers to a directory, the tar command recursively extracts that directory from the archive. If you do not specify the File parameter, the tar command extracts all of the files from the archive. When an archive contains multiple copies of the same file, the last copy extracted overwrites all previously extracted copies. If the file being extracted does not already exist on the system, the file is created. If you have the proper permissions, the tar command restores all files and directories with the same owner and group IDs as they have on the tape. If you do not have the proper permissions, the files and directories are restored with your owner and group IDs. It is not possible to ask for any occurrence of a file other than the last.
Table 3. Optional Flags Optional Flags Description -B Forces input and output blocking to 20 blocks per record. With this option, the tar command can work across communications channels where blocking may not be maintained. -b Blocks Specifies the number of 512 bytes blocks per record. Both the default and the maximum is 20, which is appropriate for tape records. Due to the size of interrecord gaps, tapes written with large blocking factors can hold much more data than tapes with only one block per record.
The block size is determined automatically when tapes are read (the -x or -t function flags). When archives are updated with the -u and -r functions, the existing record size is used. The tar command writes archives using the specified value of the Blocks parameter only when creating new archives with the -c flag.
For output to ordinary files with the -f flag, you can save disk space by using a blocking factor that matches the size of disk blocks (for example, the -b4 flag for 2048-byte disk blocks).
-C Directory Causes the tar command to perform a chdir subroutine to the directory specified by the Directory variable. Using the -C flag allows multiple directories that are not related by a close common parent to be archived, using short relative path names. For example, to archive files from the /usr/include and /etc directories, you might use the following command:
tar c -C /usr/include File1 File2 -C /etc File3 File4
You can use multiple -C options when you extract files from the archive. When you use multiple -C options, each instance of the -C Directory is relative to the one that is listed before it in the command. For example, the second -C Directory is relative to the first -C Directory.
If an archive contains a file with an absolute path name, for example /home/dir1/filename, the file is extracted into the directory that is specified by the -C Directory by removing the leading slash (/) from the filepath or filename.
The -C Directory flag must appear after all other flags and can appear in the list of file names given.
-D Suppress recursive processing when directories are specified. -d Makes separate entries for block files, special character files, and first-in-first-out (FIFO) piped processes. Normally, the tar command will not archive these special files. When writing to an archive with the -d flag, the tar command makes it possible to restore empty directories, special files, and first-in-first-out (FIFO) piped processes with the -x flag. Restriction: Although anyone can archive special files, only a user with root user authority can extract them from an archive (FIFO can also be extracted by non-root users). -E Avoids truncation of the long user and group names during addition of files to new or existing archive. -F Checks the file type before archiving. Source Code Control Systems (SCCS), Revision Control Systems (RCS), files named core, errs, a.out, and files ending in .o (dot o) are not archived. -f Archive Uses the Archive variable as the archive to be read or written. When this flag is not specified, the tar command uses a system-dependent default file name of the form /dev/rmt0. If the Archive variable specified is - (minus sign), the tar command writes to standard output or reads from standard input. If you write to standard output, the -c flag must be used.
Table 3. Optional Flags (continued) Optional Flags Description -h Forces the tar command to follow symbolic links as if they were normal files or directories. Normally, the tar command does not follow symbolic links. -i Ignores header checksum errors. The tar command writes a file header containing a checksum for each file in the archive. When this flag is not specified, the system verifies the contents of the header blocks by recomputing the checksum and stops with a directory checksum error when a mismatch occurs. When this flag is specified, the tar command logs the error and then scans forward until it finds a valid header block. This permits restoring files from later volumes of a multi-volume archive without reading earlier volumes. -L InputList The Inputlist argument to the -L option should always be the name of the file that lists the files and directories that need to be archived or extracted. -l Writes an error message to standard output for each file with a link count greater than 1 whose corresponding links were not also archived. For example, if file1 and file2 are hard-linked together and only file1 is placed on the archive, then the -l flag will issue an error message. Error messages are not displayed if the -l flag is not specified. -m Uses the time of extraction as the modification time. The default is to preserve the modification time of the files. -N Blocks Allows the tar command to use very large clusters of blocks when it deals with streaming tape archives. Note however, that on input, the tar command cannot automatically determine the block size of tapes with very long block sizes created with this flag. In the absence of a -N Blocks flag, the largest block size that the tar command can automatically determine is 20 blocks. -o Provides backwards compatibility with older versions (non-AIX) of the tar command. When this flag is used for reading, it causes the extracted file to take on the User and Group ID (UID and GID) of the user running the program, rather than those on the archive. This is the default behavior for the ordinary user. -p Restores fields to their original modes, ignoring the present umask. The setuid, setgid, and tacky bit permissions are also restored to the user with root user authority. This flag restores files and directories to their original mode. -R Use recursion when directories are specified. Ignored when used with the-D option. -s Tries to create a symbolic link If the tar command is unsuccessful in its attempt to link (regular link) two files with the -s flag.
Table 3. Optional Flags (continued) Optional Flags Description -S Blocks b, -S Feet, -S Feet@Density Specifies the number of 512KB blocks per volume (first format), independent of the tape blocking factor. You can also specify the size of the tape in feet by using the second form, in which case the tar command assumes a default Density variable. The third form allows you to specify both tape length and density. Feet are assumed to be 11 inches long to be conservative. This flag lets you deal more easily with multivolume tape archives, where the tar command must be able to determine how many blocks fit on each volume. Note:
Tape drives vary in density capabilities. The Density variable calculates the amount of data a system can fit on a tape.
When using 1/4-inch tape devices, be sure to take into account the number of tracks on the tape device when specifying the value for the Feet variable. For example, a 4-track,1/4-inch tape drive with a 600-foot tape and a density of 8000 bpi can be specified using the
-SFeet@Density flag as follows:
-S 2400@8000
where 600 feet multiplied by 4 tracks equals 2400 feet.
-U Archives or restores named extended attributes and ACLs. When listing, this option will display the names of any named extended attributes and the type of any ACLs associated with each file that are part of the archive image. -v Lists the name of each file as it is processed. With the -t flag, -v gives more information about the tape entries, including file sizes, times of last modification, User Number (UID), Group Number (GID), and permissions. -w Displays the action to be taken, followed by the file name, and then waits for user confirmation. If the response is affirmative, the action is performed. If the response is not affirmative, the file is ignored. -Number Uses the /dev/rmtNumber file instead of the default. For example, the -2 flag is the same as the -f/dev/rmt2 file. -X ExcludeList Excludes the file names or directories given in the ExcludeList from the tar archive being created, extracted or listed. The ExcludeList shall contain only one filename or directory per line which are to be excluded from the tar archive being created, extracted from or listed. The -X option can be specified multiple times and it takes precedence over all other options. -Z Archives the Encrypted File System (EFS) information of encrypted files or directories. The EFS information is extracted by default. When you specify the -t and -v flags along with the -Z flag, an e indicator is displayed after the file mode for encrypted files and directories that were archived with the -Z flag, and a hyphen (-) is displayed after the file mode for other files. Restriction: Archives created with the -Z flag 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.
예제
| 명령 | 하는 일 |
|---|---|
tar -c file1 file2 |
file1, file2를 기본 테이프에 새 아카이브로 씀 |
tar -xm -f/dev/rmt2 /tmp |
테이프 /dev/rmt2에서 /tmp의 파일을 모두 꺼내고 꺼낸 시각을 수정 시각으로 씀 |
tar -cvf - file1 | dd of=/dev/rmt1 conv=sync |
file1로 아카이브를 만들어 dd로 /dev/rmt1에 씀 |
tar -vtf out.tar |
현재 디렉터리의 디스크 아카이브 out.tar의 파일 이름 목록 |
zcat fil.tar.Z | tar -xvf - |
압축한 tar 아카이브 fil.tar.Z를 풀어 모든 파일을 꺼냄 |
tar -cvf /dev/rmt0 -S 4800000b /usr |
8mm 장치에 -S를 써서 보관. 8mm는 밀도 개념이 없어 -S Feet, -S Feet@Density는 피함 |
tar -cvf fl.tar -L fl_list |
ls *.c > fl_list로 만든 목록 파일의 C 파일을 보관 |
tar -cvEf file.tar file |
긴 사용자·그룹 이름을 자르지 않고 보관 |
tar -cvUf /tmp/tar.ar file1 |
ACL과 확장 속성(EA)까지 file1을 보관 |
/usr/include와 /usr/bin을 짧은 상대 경로로 보관합니다. 두 번째 -C는 첫 번째 -C 기준이라 ../bin입니다.
cd /usr
tar -cvf/dev/rmt0 -C./include . -C ../bin .
변수로 목록 파일을 줄 수도 있습니다.
ls *.c > fl_list
fl=fl_list
tar -cvf var.tar -L $fl
Berkeley 형식 예
플래그 인수는 플래그를 쓴 순서대로 줍니다. 예를 들어 tar cvfbL test.tar 20 infile에서 test.tar는 아카이브, 20은 블록 수, infile은 입력 목록입니다.
| 명령 | 하는 일 |
|---|---|
tar cvfL ar.tar infile |
목록 파일 infile에 있는 디렉터리와 파일을 ar.tar에 보관 |
tar cvRfL ar.tar infile |
목록의 디렉터리 안 파일까지 재귀로 보관 |
tar xvfL ar.tar infile |
ar.tar에서 목록의 디렉터리와 파일을 꺼냄 |
tar xvRfL ar.tar infile |
목록의 디렉터리 안 파일까지 재귀로 꺼냄 |
자주 쓰는 형태:
cd /data && tar -cvf /backup/app.tar ./app # 상대 경로로 만들기
tar -cvf - ./app | gzip > /backup/app.tar.gz # 압축(AIX tar에는 -z 없음)
gunzip -c /backup/app.tar.gz | tar -xvf - # 압축 풀며 꺼내기
tar -tvf /backup/app.tar | more # 내용 확인
tar -cvf - ./app | ssh host2 "cd /data && tar -xvpf -" # 다른 서버로 복사
영어 원문
- To write the
file1andfile2files to a new archive on the default tape drive, enter:
tar -c file1 file2
- To extract all files in the
/tmpdirectory from the archive file on the/dev/rmt2tape device and use the time of extraction as the modification time, enter:
tar -xm -f/dev/rmt2 /tmp
- To create a new archive file that contains the
file1file and pass the archive file to the dd command to be written to the/dev/rmt1device, enter:
tar -cvf - file1 | dd of=/dev/rmt1 conv=sync
- To display the names of the files in the
out.tardisk archive file on the current directory, enter:
tar -vtf out.tar
- To expand the compressed tar archive file,
fil.tar.z, pass the file to the tar command, and extract all files from the expanded tar archive file, enter:
zcat fil.tar.Z | tar -xvf -
- To archive the contents of
/usr/includeand/usr/binfiles using short relative path names, enter:
cd /usr
tar -cvf/dev/rmt0 -C./include . -C ../bin .
Requirement: When specifying multiple instances of the -C flag with relative path names, the user must take the previous -C flag request into account.
- To archive to an 8-mm device when using the
-Sflag, enter:
tar -cvf /dev/rmt0 -S 4800000b /usr
Restriction: When archiving to an 8-mm device, avoid using the -S Feet and -S Feet@Density flags, because the 8-mm device does not use the concept of density when writing to a tape.
- To archive a list of all
Cfiles that is listed in the file through the InputList argument of the-Loption, enter:
tar -cvf fl.tar -L fl_list
Where fl_list is a file consisting a list of all .c files in it. This can be obtained as follows:
ls *.c > fl_list
- To archive a list of all
Cfiles by setting a variable using the-Loption, enter:
ls *.c > fl_list
fl=fl_list
tar -cvf var.tar -L $fl
- To avoid the truncation of long user or group names during creation of the archive, enter:
tar -cvEf file.tar file
- To create a new archive file that contains the
file1file with ACL and EA, enter:
tar -cvUf /tmp/tar.ar file1
Berkeley Options
The following are examples of the Berkeley options using the tar command:
Tip: With Berkeley options the arguments to the flags should be given in exact order in which the flags are given below. For example: tar cvfbL test.tar 20 infile
where test.tar is archive tar file, 20 is number of blocks, and infile is Inputlist for the archive.
- To archive all directories and complete filenames listed in input list file infile into ar.tar, enter :
tar cvfL ar.tar infile
Where infile contains the pathnames of files that are to be archived.
To archive files within directories listed in the input list file infile into ar.tar, enter:
tar cvRfL ar.tar infileTo extract directories and complete files specified in the input list file infile from an archive named ar.tar, enter:
tar xvfL ar.tar infileTo extract files from within directories and complete files specified in the input list file infile from an archive named ar.tar, enter:
tar xvRfL ar.tar infile
파일
| 파일 | 설명 |
|---|---|
/dev/rmt0 |
기본 테이프 장치 |
/bin/tar |
tar 명령으로의 심볼릭 링크(AIX 3.2부터 /bin 전체가 /usr/bin으로의 링크) |
/usr/bin/tar |
tar 명령 |
/tmp/tar* |
임시 파일 |
영어 원문
- /dev/rmt0 — Specifies the default tape device.
- /bin/tar — Specifies the symbolic link to the tar command.
- /usr/bin/tar — Contains the tar command.
/tmp/tar*— Specifies a temporary file.- Tip: In AIX 3.2, the entire /bin directory is a symbolic link to /usr/bin.
Related information:
- cat command
- dd command
- rmt command
- File systems
- Directory Overview
리눅스(GNU)와 다른 점
리눅스의 GNU tar도 -c, -t, -x, -r, -u, -v, -f, -C, -p의 뜻이 같습니다. 다만 GNU tar는 -z(gzip), -j(bzip2), -J(xz) 압축을 직접 하고, 절대 경로의 앞 /를 기본으로 떼며, -T(목록 파일), --exclude·-X(제외)를 씁니다. 기본 아카이브도 테이프가 아니라 -f를 꼭 줘야 합니다. AIX에서 GNU tar가 필요하면 AIX Toolbox의 gtar를 씁니다.