0% found this document useful (0 votes)
238 views1 page

The Tar Command Cheat Sheet: Format

The tar command allows users to create, extract, and list archives. It supports various compression formats like gzip and bzip2. Gzip tends to be faster and more compatible than bzip2, creating smaller file sizes. The tar command syntax includes options like "c" to create, "x" to extract, "t" to list, "f" to specify a file name, "v" for verbose output, "z" for gzip compression, and "j" for bzip2. Examples show how to list, create, and extract archives with tar.

Uploaded by

Farha Azad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views1 page

The Tar Command Cheat Sheet: Format

The tar command allows users to create, extract, and list archives. It supports various compression formats like gzip and bzip2. Gzip tends to be faster and more compatible than bzip2, creating smaller file sizes. The tar command syntax includes options like "c" to create, "x" to extract, "t" to list, "f" to specify a file name, "v" for verbose output, "z" for gzip compression, and "j" for bzip2. Examples show how to list, create, and extract archives with tar.

Uploaded by

Farha Azad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The ​tar​ Command Cheat Sheet 

Format: ​tar <OPTIONS> [ARCHIVE NAME] [DIRECTORY OR FILE NAMES]...


 

Option  Description 

c  Create an archive 

x  Extract from an archive 

t  List the contents of an archive 

f  Specify a file name for the archive (as opposed to using stdin or stdout) 

v  Verbose output (optional, but recommended) 

z  Use gzip for compression 

j  Use bzip2 for compression 

p  Preserve file permissions (active by default for superuser) 


 
Note that options can be specified with or without a dash in front of them (both "-xvzf" and "xvzf" 
work the same). On compression, gzip tends to pack and unpack faster and is supported on more 
platforms, while bzip2 creates smaller archives. When in doubt, use gzip. 

Command Examples 

List the files in a gzipped archive. 


tar -tzf archivename.tar.gz

Create an archive from a directory 


tar -cvf archivename.tar directoryname

Extract the files from an archive 


tar -xvf archivename.tar

Create a gzipped archive with specific files 


tar -czvf archivename.tar.gz filename1.txt directoryname/filename2.html

Extract specific files from a bzipped tar archive 


tar -xjvf archivename.tar.bz2 filename1.txt directory/filename2.html

Extract files from a gzipped archive while preserving file permissions as a non-root user (e.g. 
to preserve the executable bits on extracted shell scripts) 
tar -xvzpf archivename.tar.gz 

LinuxTrainingAcademy.com 

You might also like