tar
file managementLinux/Unix
The tar command is one of the most frequently used commands in Linux/Unix-like operating systems. tar Tape Archive: create, extract, and manipulate archive files
Quick Reference
Command Name:
tar
Category:
file management
Platform:
Linux/Unix
Basic Usage:
tar -czvf archive.tar.gz directory/
Common Use Cases
Syntax
tar [options] [archive-file] [file or directory to be archived]
Options
Option | Description |
---|---|
-c, --create |
Create a new archive |
-x, --extract, --get |
Extract files from an archive |
-t, --list |
List the contents of an archive |
-f, --file=ARCHIVE |
Use archive file or device ARCHIVE |
-v, --verbose |
Verbosely list files processed |
-z, --gzip, --gunzip |
Filter the archive through gzip |
-j, --bzip2 |
Filter the archive through bzip2 |
-J, --xz |
Filter the archive through xz |
--zstd |
Filter the archive through zstd |
-a, --auto-compress |
Use archive suffix to determine the compression program |
-C, --directory=DIR |
Change to directory DIR before operation |
-p, --preserve-permissions |
Extract information about file permissions |
--exclude=PATTERN |
Exclude files matching PATTERN |
-r, --append |
Append files to the end of an archive |
-u, --update |
Only append files newer than copy in archive |
-P, --absolute-names |
Don't strip leading '/' from file names |
--strip-components=NUMBER |
Strip NUMBER leading components from file names on extraction |
--transform=EXPRESSION, --xform=EXPRESSION |
Use sed replace EXPRESSION to transform file names |
-k, --keep-old-files |
Don't replace existing files when extracting |
-g, --listed-incremental=FILE |
Handle new GNU-format incremental backup |
--help |
Display help information |
--version |
Display program version |
Examples
How to Use These Examples
The examples below show common ways to use the tar
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
# Create a tar archive
tar -cf archive.tar file1 file2 directory1