Create a basic tar archive:
tar -cf archive.tar /path/to/files
-c
: create a new archive.
-f
: specify the archive file name.
A comprehensive cheat sheet for the tar (tape archive) command, covering common operations like creating, extracting, compressing, and listing archives, along with practical examples.
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:
|
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:
|
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:
|
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. |
Exclude specific files or directories when creating an archive:
|
Using a file containing a list of patterns to exclude:
|
Using gzip for compression:
Suitable for general-purpose compression. |
Adjusting gzip compression level (1-9, default is 6):
|
Using bzip2 for compression:
Generally provides better compression than gzip but is slower. |
Adjusting bzip2 compression level (1-9):
|
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):
|
‘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. |
For very large archives, consider using
Then, use them with
|
Older versions of
|