tar - Create & Extract

Mastering tar

Everyone forgets tar's flags, so learn them as words:

Tip: Read tar -czf as "Create Zipped File" and tar -xzf as "eXtract Zipped File". That mnemonic ends the confusion forever.
CommandDoes
tar -cvf backup.tar dir/Create archive from dir
tar -czf backup.tar.gz dir/Create gzip-compressed archive
tar -xzf backup.tar.gzExtract a gzip tarball
tar -tzf backup.tar.gzList contents without extracting
tar -xzf f.tgz -C /destExtract into a specific directory
$ tar -czf logs.tar.gz /var/log
$ tar -tzf logs.tar.gz | head -3
var/log/
var/log/syslog
var/log/auth.log
Warning: The f flag must come last among grouped flags because the filename follows it. tar -czf name.tar.gz ✅, but tar -cfz name.tar.gz treats z as the filename. ❌