クイックリファレンス

tar コマンド・アーカイブ作成・gzip圧縮解凍早見表

UNIX tarコマンドのクイックリファレンス:アーカイブの作成(-c)、一覧表示(-t)、展開(-x)、gzip/bzip2圧縮連携(-z/-j)。

· 公開日

The tar utility archives, bundles, and extracts file trees on Linux and Unix systems.

Common Operations

Compress and Archive

# Create gzip-compressed archive (.tar.gz)
tar -czf archive.tar.gz /path/to/files

# Create uncompressed archive (.tar)
tar -cf archive.tar /path/to/files

# Create bzip2-compressed archive (.tar.bz2)
tar -cjf archive.tar.bz2 /path/to/files

Extract Archive

# Extract gzip-compressed archive in current directory
tar -xzf archive.tar.gz

# Extract archive to a target directory
tar -xzf archive.tar.gz -C /target/directory

# Extract plain tar archive
tar -xf archive.tar

List and Inspect

# List archive contents without extracting
tar -tzf archive.tar.gz

# List archive contents verbosely with details
tar -tvzf archive.tar.gz

Append Files

# Append file to existing uncompressed archive
tar -rf archive.tar new_file.txt

# Update files newer than archive copy
tar -uf archive.tar changed_file.txt

Option Flags Reference

Flag Name Description
-c --create Create a new archive
-x --extract Extract files from an archive
-t --list List table of contents
-z --gzip Filter archive through gzip
-j --bzip2 Filter archive through bzip2
-f --file Use specified archive file name
-v --verbose Verbosely list processed files
-C --directory Change to target directory before operations
-u --update Only append files that are newer than archive copy

関連テーマ