← Files & Text
Linux · Files & Text
How to create and extract tar archives in Linux
Create, list, and extract tar archives with gzip compression, and extract safely by listing contents first.
Bundle files into a tar archive, optionally gzip-compressed (.tar.gz). Remember the letters: c=create, x=extract, t=list, f=file, z=gzip, v=verbose.
Extracting an archive overwrites existing files with the same names in the target directory. List the contents with -t first, and extract into a clean directory when unsure.
# Create a gzip-compressed archive
tar czvf backup.tar.gz /etc/myapp
# List the contents (check before extracting)
tar tzvf backup.tar.gz
# Extract into a specific directory
tar xzvf backup.tar.gz -C /restore
# Compress / decompress a single file
gzip bigfile
gunzip bigfile.gzLinuxtarArchive