Catalog / Tar Command Cheatsheet
Tar Command Cheatsheet
A comprehensive cheat sheet for the tar (tape archive) command, covering common operations like creating, extracting, compressing, and listing archives, along with practical examples.
Basic Operations
Creating Archives
Create a basic tar archive:
|
Create a gzipped tar archive:
|
Create a bzip2 compressed tar archive:
|
Create a xz compressed tar archive:
|
Adding verbosity to creation:
|
Extracting Archives
Extract a tar archive:
|
Extract a gzipped tar archive:
|
Extract a bzip2 compressed tar archive:
|
Extract a xz compressed tar archive:
|
Extracting with verbosity:
|
Extract to specific directory:
|
Advanced Usage
Listing Archive Contents
List the contents of a tar archive:
|
List the contents of a gzipped tar archive:
|
List the contents of a bzip2 compressed tar archive:
|
List the contents of a xz compressed tar archive:
|
Listing verbosely:
|
Appending Files
Append files to an existing tar archive:
Note: Appending to compressed archives is not directly supported. You’ll need to extract, append, and then re-compress. |
Excluding Files
Exclude specific files or directories when creating an archive:
|
Using a file containing a list of patterns to exclude:
|
Compression Options
Gzip
Using gzip for compression:
Suitable for general-purpose compression. |
Adjusting gzip compression level (1-9, default is 6):
|
Bzip2
Using bzip2 for compression:
Generally provides better compression than gzip but is slower. |
Adjusting bzip2 compression level (1-9):
|
XZ
Using xz for compression:
Offers the best compression ratio but is the slowest. Good for archiving data for long-term storage where space is a premium. |
Adjusting xz compression level (0-9):
|
Troubleshooting
Common Issues
‘Cannot open: No such file or directory’ Verify the path to the archive or files exists and is accessible. |
‘Not in gzip format’ or similar errors during extraction Ensure you are using the correct extraction flag ( |
Permission denied errors Use |
Truncated or Corrupted Archive This may happen if the archive creation was interrupted or the download was incomplete. Try recreating the archive or re-downloading it. |
Large Files and Archives
For very large archives, consider using
Then, use them with
|
Filename Length Limitations
Older versions of
|