Table of Contents
File Compression and Decompression in Linux:
Compressing Files or Directories:
Using gzip:
gzip filenameThis command compresses the filename and creates a compressed file named filename.gz.
Using bzip2:
bzip2 filenameThis command compresses the filename and creates a compressed file named filename.bz2.
Using xz:
xz filenameThis command compresses the filename and creates a compressed file named filename.xz.
Using tar for Compression (with gzip):
tar -czvf archive.tar.gz directoryThis command creates a compressed archive file archive.tar.gz containing the directory. The options include -c for creating a new archive, -z for gzip compression, -v for showing detailed progress, and -f for specifying the file name.
Decompressing Compressed Files:
Using gzip:
gzip -d filename.gzThis command decompresses the filename.gz and leaves the original file as filename.
Using bzip2:
bzip2 -d filename.bz2This command decompresses the filename.bz2 and leaves the original file as filename.
Using xz:
xz -d filename.xzThis command decompresses the filename.xz and leaves the original file as filename.
Using tar for Decompression (with gzip):
tar -xzvf archive.tar.gzThis command extracts the contents of the archive.tar.gz and shows detailed progress. The options include -x for extracting an archive, -z for gzip decompression, -v for detailed progress, and -f for specifying the file name.
By using these commands, you can compress and decompress files and directories in Linux. Choose the appropriate compression method based on your use case and requirements.