- Home
-
TAR Command
TAR Command Cheatsheet for SysAdmin
Comprehensive TAR (Tape Archive) command guide covering archive creation, extraction, compression (gzip, bzip2, xz), file manipulation, and essential options for Linux system administrators. Essential for managing backups on VPS servers and optimizing storage on performance-tested hosting environments.
Free account required
Usage
$ tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG...]
Description: GNU tar is an archiving program that allows you to store multiple files in a single file (an archive) and manipulate them. The archive can be a regular file or a device (for example, a tape drive), which stands for tape archiver, and it can be located on a local machine or a remote machine. Often combined with grep for searching archived content or used alongside other essential Linux commands for file management workflows.
Table of Contents
Common Use Cases
- Server Backups: Create automated backups using cron jobs for scheduled archiving of critical data on your VPS
- Container Backups: Archive Docker volumes and configuration files for disaster recovery
- File System Management: Navigate and compress directories efficiently within the Linux filesystem hierarchy
- Remote Transfers: Combine with curl or SSH for secure file transfers between servers
Common Options
Option | Description |
---|---|
-A | Append archive to the end of another archive. |
-c | Create a new archive. Directories are archived recursively, unless the --no-recursion option is given. |
-d | Find differences between archive and file system. |
--delete | Delete provided members from an archive. |
-r | Append files to the end of an archive. |
-t | List the contents of an archive. |
-u | Append files which are newer than the corresponding copy in the archive. |
-x | Extract files from an archive. |
-? or --help | Display a short option summary and exit. |
-k | Don't replace existing files when extracting. |
-O | Extract files to standard output. |
-p | filename of the archive. |
-v | Verbosely list files processed. |
-z | Compress files with gzip. |
-j | Compress files with bzip2. |
-J | Compress files with xz. |
-Z | Compress files with compress. |
-a | Use archive suffix/extension to determine the compression program. |
-C | Changes to the specified directory before performing any operation. |
--exclude=FILE | Excludes the FILE when adding to tar archive or extracting from a tar archive. |
Options Examples
Concatenate files into a single tarball called archive.tar
$ tar -cf archive.tar file1 file2 fileN
List the contents of archive without extracting.
$ tar -tf archive.tar
Concatenate all files in a directory into a single tarball, called archive.tar
$ tar -cf archive.tar *
Archive only .php files.
$ tar -cf archive.tar *.php
Extract files from the tar archive file.
$ tar -xf archive.tar
Extract specific file from an archive.
$ tar -xf archive.tar file1 file2
List the contents of an archive.
$ tar -tf archive.tar
Append files to an existing archive.
$ tar -rf archive.tar file_to_append
Merge archive2.tar into archive.tar
$ tar -Af archive.tar archive2.tar
Delete files from an archive.
$ tar --delete archive.tar file_to_delete
Find differences between an archive and file.
$ tar -df archive.tar file1
Append only new files to the archive.
$ tar -uf archive.tar new_files
Create an archive and compress it with gzip utility.
$ tar -czf archive.tar.gz file1 file2
Create an archive and compress it with bzip2 utility.
$ tar -cjf archive.tar.gz file1 file2
Extract archive into a specific directory.
$ tar -xf archive.tar -C directory-path
Exclude config.php file while creating an archive
$ tar -cf archive.tar * --exclude=config.php
Related Tools & Commands
Master these complementary commands to enhance your file management and archiving workflows on Linux systems.
Grep Command
Search through archived files and list contents matching specific patterns
Sed Command
Stream editor for modifying files before or after archiving operations
Essential Linux Commands
Complete reference for file operations, navigation, and system administration
Curl Command
Transfer archives to remote servers or download compressed files efficiently
Master System Administration on Reliable VPS Hosting
Ready to manage archives and backups on professional infrastructure? Explore our curated VPS providers, check out how we test performance, and find the perfect hosting solution for your needs.
Platform
Resources
Company
Learn system administration and Linux commands for managing your VPS infrastructure efficiently