Beginner LevelLinux Commands & SysAdmin
How do tar, gzip, and bzip2 create and extract compressed archives?
❓ Interview Prompt: Explain tar flags (-c, -x, -z, -j, -v, -f), creating tarballs (.tar.gz, .tar.bz2), and extracting archives.
The 'tar' (Tape Archive) utility bundles multiple files into a single archive file, combined with compression algorithms:
Common Flags:
•
'-c': Create archive | '-x': Extract archive
•
'-v': Verbose output | '-f': Archive filename
•
'-z': Use gzip compression ('.tar.gz' / '.tgz')
•
'-j': Use bzip2 compression ('.tar.bz2')
Code Implementation Example
bash
# Create compressed tar.gz archive of website directory
tar -czvf backup-2026.tar.gz /var/www/app
# Extract archive into target directory
tar -xzvf backup-2026.tar.gz -C /opt/restored/💡Creating and extracting gzipped tar archives.
🎯 Interview Key Takeaway
Use tar -czvf to create .tar.gz compressed archives, and tar -xzvf to extract them.
#tar#gzip#Compression#Archives#Beginner
Back to all Linux Commands & SysAdmin Questions→