Need to extract a bzip2 or gzip file? well here’s how to do it : Bzip2 in the file.bz2 format : bunzip2 file.bz2 a tar file with bzip2 compression : tar xjvf file.tar.bz2 A tar file with no compression : tar xvf file.tar A tar file with Gzip compression : tar zxvf file.tar.gz tar zxvf file.tgz A 7zip file : 7z x file.7z 7z x file.zip Rar Files : unrar x file.rar
yum -y install xz Want to keep lots of logs, yet don’t want them cluttering up your logs directory and want them taking as little space as possible? well lets use a handy utility called logrotate and a compression utility called xz. xz is a lossless data compression program and file format which incorporates the LZMA/LZMA2 compression algorithms. Due to its better compression its great for logrotate so we can compress our existing logs better and end up storing more logs, which helps diagnose issues and facilitates better audit trails. Install logrotate and xz-utils. Debian / Ubuntu: apt-get install logrotate xz-utils Centos / Redhat: yum -y install xz Make a directory for the old logs. mkdir /var/log/old now open up nano /etc/logrotate.conf Edit at will then at the bottom insert this compress compresscmd /usr/bin/xz uncompresscmd /usr/bin/unxz compressext .xz compressoptions -9 olddir /var/log/old voila ! you are done. feel free to change the -9 to any number between -1 and -9 the lower the number the lower the compression but also lower the cpu/ram usage during said compression.
Compression types and utils in Linux There are many compression utilities available to the average users on a linux system, so which one is best? well it all depends on what your intended use/goal for the file(s) is. Are you planning on sending the file to other OS’s? are you planning on decompressing the file on a new system where you might not have the same tools available? etc etc. I am writing about some of the ones I have used, and since this is from my usage some of it may not be entirely true and I may have dreamed up during my hallucinatory state while attending classes. Zip The Most popular tool, archives and provides basic compression. Works on most OS’s popularly used today. zip <filename> <files to compress> —– zip files into one archive zip mydocs.zip doc1 doc2 doc3 doc4 unzip <filename> —– unzip files from an archive into their proper paths under current directory. unzip -j <filename> —– unzip files from the archive into current directory not following directory structure. Tar Archive only, no compression applied by default. usually found with .tar extension tar -cf —– tar multiple files into one archive with no compression (see bzip2 / gzip for compression) tar -xf <filename> —– extract files from a tarball Rar Proprietary but with support for almost all popular platforms, decent compression + archival. usually found with .rar extension rar a <filename> <files to compress> —– archive + compress unrar x <filename> […]