Linux provides several tools for compressing and decompressing files. Compression reduces file size, saves storage, and makes transfers faster. Below are the most commonly used commands.

Compressing with gzip

gzip filename

Creates filename.gz and removes the original file.

Keep the original file:

gzip -c filename > filename.gz

Compressing with bzip2

bzip2 filename

Creates filename.bz2.

Keep the original file:

bzip2 -k filename

Compressing with xz (LZMA)

xz filename

Creates filename.xz.

Keep the original file:

xz -k filename

Uncompressing Files

.gz files

gunzip filename.gz

or

gzip -d filename.gz

.bz2 files

bunzip2 filename.bz2

or

bzip2 -d filename.bz2

.xz files

unxz filename.xz

or

xz -d filename.xz

Compressing Multiple Files with tar

Compression tools normally work on single files. To handle multiple files or directories, create a tar archive and then compress it.

gzip:

tar -czvf archive.tar.gz file1 file2 directory/

bzip2:

tar -cjvf archive.tar.bz2 file1 file2 directory/

xz:

tar -cJvf archive.tar.xz file1 file2 directory/

Options:

  • c = create archive
  • z/j/J = compress with gzip/bzip2/xz
  • v = verbose (show process)
  • f = file name

Need Help with Migration?

If you are planning a server migration or large-scale data transfer, it’s safer to have experts handle it. You can hire our administrators for dedicated hours to manage migration, backups, and server optimization.

Bu cevap yeterince yardımcı oldu mu? 0 Bu dökümanı faydalı bulan kullanıcılar: (0 Oy)