Cheatsheet: Tar

Basic Archiving Commands

Create an archive from a directory

tar -cvf archive_name.tar /path/to/directory

Create a compressed archive using gzip

tar -czvf archive_name.tar.gz /path/to/directory

Create a compressed archive using bzip2

tar -cjvf archive_name.tar.bz2 /path/to/directory

Create an archive from multiple files

tar -cvf archive_name.tar file1 file2 file3

Extracting Archives

Extract a tar archive

tar -xvf archive_name.tar

Extract a gzip-compressed tar archive

tar -xzvf archive_name.tar.gz

Extract a bzip2-compressed tar archive

tar -xjvf archive_name.tar.bz2

Extract to a specific directory

tar -xvf archive_name.tar -C /path/to/destination

Listing & Verifying Archive Contents

List the contents of an archive

tar -tvf archive_name.tar

List the contents of a gzip-compressed archive

tar -tzvf archive_name.tar.gz

List the contents of a bzip2-compressed archive

tar -tjvf archive_name.tar.bz2

Verify the integrity of an archive

tar -tvf archive_name.tar

Advanced Options

Add files to an existing archive

tar -rvf archive_name.tar new_file

Delete a file from an archive (use with caution)

tar --delete -f archive_name.tar file_to_remove

Create an archive and split it into multiple parts

tar -cvf - /path/to/directory | split -b 500M - archive_part

Extract a single file from an archive

tar -xvf archive_name.tar file_name