Tar
lastmod 2026-02-06created 2014-08-0621 edits
In computing, tar refers both to a file format designed for tape archives and to the program used to handle files in that format. The file format was created in the early days of Unix and was standardized by POSIX.1-1988 and POSIX.1-2001.
It was originally developed for tape backups, to write directly to sequential I/O devices, but today it is mainly used to bundle many files into one large file for distribution or archiving while preserving the directory structure and file attributes.
Flags
-
-c: When compressing. -
-x: When extracting. -
-t: When checking the contents of an archive. -
-f: When using an archive file. -
-p: Preserve permissions when compressing and extracting. -
-v: Show progress when compressing and extracting. -
-z: Use gzip. -
-j: Use bzip.
List the contents
- List the contents of a tar file
- List the contents of a tar.gz file
- List the contents of a tar.bz2 file
Specifying the output directory path
Use the -C option to specify the output directory path.
Splitting and joining files
Use the split and cat commands.
# Split tar file into 4G chunks / tar 파일을 4G 단위로 분할
split -b 4G archive.tar archive.tar.part_
# Merge back / 다시 합치기
cat archive.tar.part_* > archive.tar
Adding split -d makes the suffixes numeric (part_00, part_01, ...).
Receiving a pipe from CURL
curl -L https://github.com/slackhq/nebula/releases/download/v1.9.1/nebula-linux-amd64.tar.gz | tar xzf - -C ~/bin
Things to note:
- A pipe needs
-. - Changing the output location needs
-C {dir}, which must come after-(i.e. argument order matters) - sudo cannot be used in front of curl. So you have to enter first with something like
sudo -sand then start.
Absolute path
If you don't want absolute paths to be stripped, which happens automatically when compressing, use the --absolute-names or -P option.
Remove first-depth directory
If you want to extract after stripping the directory path of the archived files, use the --strip-components=NUMBER option.
Your command would be:
See also
- unzip
- gzip
- hop (Archive Format) - An archive format 10 times faster than tar
- Python:tarfile - Python's tar archive library.
- Unblob - A tool that extracts files from various formats
- 7z
Favorite site
- Wikipedia (en) Description of TAR
- Simple TAR usage
- Why is GNU tar slow at extracting? | GeekNews
- [Original] The tar archive format, its extensions, and why GNU tar extracts in quadratic time
- The investigation started because extracting a 518GiB tar.gz became extremely slow
- Explains the tar format and walks through writing a fast tar extractor
- Conclusion: use the
--sortoption.