Linux – Compressing and archiving data

, <span>Linux – Compressing and archiving data</span>, KandZ

You can compress data with the following commands:

  • gzip  – It is the most frequenlty compression utility
  • bzip2  – Better compression rate than gzip
  • xz  – The most space efficient compression utility
  • zip  –  Small use in linux, just to examine and decompress archices from other OS like Windows

 

gzip

gzip *  #compress all files and each file renamed with .gz extension

gzip -r directoryToCompress #   compress all files and directories in the directory directoryToCompress

gunzip compressedFile.gz  # uncompress a compressed file. It is the same as gzip -d  compressedFile

 

bzip2

Similar syntax to gzip but it uses different algorithm to compress the files

bzip *  # compress all files and each file renamed with .bz2 extension

bunzip2  bzipfile.bz2 # decompress in the current directory. The same as bzip -d

 

xz

xz * # the same as gzip and bzip2

xz file # compress file to file.xz. Also removes the normal file

xz -dk file.xz #decompress file.xz into file and don't remove the file.xz

xz -dcf 1.txt 2.txt.xz > newfile.txt  # decompress a mix of compressed and uncompressed files to standard output

xz -d *.xz  # decompress files

 

zip

zip backup *  # compress all files in the directory 

zip -r backup.zip /etc  # compress all the files and directories in /etc

unzip backup.zip  #decompress zip files

 

tar

tar xvf  mydir.tar  # extract an tarball file

tar zcvf myhome.tar.gz  /home/user  # create and compress the archive with gzip

tar jcvf myhome.tar.gz /home/user  # create and compress the archive with bzip2

tar Jcvf myhome.tar.xz  /home/user  # create and compress the archive with xz

tar xvf  myhome.tar.gz # extract all files and you do not need to tell tar that it is in a gzip format
21200cookie-checkLinux – Compressing and archiving dataLinux – Compressing and archiving data

Related posts

Leave a Comment