How to compress and decompress files or directories in Linux

In Linux, the tar command can be used to compress and decompress files or directories. Here are some commonly used compression and decompression operations:

  1. Compress file or directory.
tar -czvf archive.tar.gz /path/to/file_or_directory

-c option is used for creating a compressed file, -z option is used for using the gzip compression algorithm, -v option is used for displaying detailed information, and -f option is used for specifying the name of the compressed file.

  1. Unzip files or directories.
tar -xzvf archive.tar.gz

-x is for decompressing files, -z is for using the gzip decompression algorithm, -v is for displaying detailed information, and -f is for specifying the compressed file to be decompressed.

In addition to the gzip compression algorithm, other compression algorithms such as -j for bzip2 and -J for xz can also be used for compression.

Additionally, you can also use the zip command to compress and decompress files in zip format.

zip archive.zip /path/to/file_or_directory
unzip archive.zip
Leave a Reply 0

Your email address will not be published. Required fields are marked *