Here’s a basic tar
command cheat sheet:
Tar Command Basics
Create a Tar Archive
tar -cvf archive.tar file1 file2 directory/
- Options:
-c
: Create a new archive.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
Extract Tar Archive
tar -xvf archive.tar
- Options:
-x
: Extract files from an archive.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
Create a Gzipped Tar Archive (tgz)
tar -cvzf archive.tar.gz file1 file2 directory/
- Options:
-c
: Create a new archive.-v
: Verbose mode (show the progress).-z
: Use gzip compression.-f
: Specify the archive file name.
Extract Gzipped Tar Archive (tgz)
tar -xzvf archive.tar.gz
- Options:
-x
: Extract files from an archive.-z
: Use gzip compression.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
List Contents of a Tar Archive
tar -tvf archive.tar
- Options:
-t
: List the contents of an archive.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
Create a Bzipped Tar Archive (tbz)
tar -cvjf archive.tar.bz2 file1 file2 directory/
- Options:
-c
: Create a new archive.-v
: Verbose mode (show the progress).-j
: Use bzip2 compression.-f
: Specify the archive file name.
Extract Bzipped Tar Archive (tbz)
tar -xjvf archive.tar.bz2
- Options:
-x
: Extract files from an archive.-j
: Use bzip2 compression.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
Additional Options
Extract to a Specific Directory
tar -xvf archive.tar -C /path/to/directory
- Options:
-x
: Extract files from an archive.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.-C
: Change to the specified directory before extracting.
Create an Incremental Backup
tar --create --file=backup.tar --listed-incremental=snapshot.snar /path/to/files/
- Options:
--create
: Create a new archive.--file
: Specify the archive file name.--listed-incremental
: Create or update a snapshot file for incremental backups.
Extract Specific Files
tar -xvf archive.tar file1 file2
- Options:
-x
: Extract files from an archive.-v
: Verbose mode (show the progress).-f
: Specify the archive file name.
These examples cover some common tar
commands. For more detailed information, refer to the tar
manual or documentation by running man tar
in your terminal.