Basic Linux TutorialIntroduction – What is it? Why to learn? Linux installation directory structures Boot process Run levels in Linux Desktop Environments Different shells BASH Internal and External Commands Basic Linux Commands Important files and directories in Linux Environmental and Shell Variables Command history in Linux Character classes in Linux Text editors vim nano Searching files Creating new files Viewing File Contents File commands File permissions and ownership WildCards (Globbing) in files File compression Directory commands xargs command in Linux Comparing files Searching patterns using grep command Translating the characters using tr command Extracting data using cut command Stream editing using sed command Data extraction and reporting using awk command Sorting the file or string input uniq command in Linux Difference between grep, tr, cut, sed and awk commands Hardware commands Hard disk and memory space commands Working with Processes Managing Jobs Working with cron jobs Service command in Linux Network commands Managing Users and Groups Other Popular commands Standard streams and Redirection Pipes Package Managers in Linux
Archiving and compression in linux shellWe can use zip and tar commands to archive and compress the files in Linux.
Archiving and Compressing using zip commandYou can use below command to zip file abc.txt into abc.zip
You will get below error if you do not provide the .zip destination file.
$ zip abc.zip abc.txt
To compress directory, you need to use -r option. It means zip files recursively. Below command can be used to unzip the zipped files.
zip error! nothing to do
Below command will list the zipped files without extraction.
$ unzip abc.txt.zip
$ unzip -l abc.txt.zip
Compressing files using gzip commandgzip uses deflat algorithm to compress data. Below command will compress the abc.txt file to abc.txt.gz
To compress directory, you need to use -r option. It means zip files recursively. To uncompress any .gz file, you can use below command. Note that gunzip is an alias for below command.
$ gzip abc.txt
Note that zcat is an alias for below command.
$ gzip -d <file-name>.gz
$ gunzip -c <file-name>.gz
Compressing files using bzip2 commandbzip2 uses Burrows-Wheeler algorithm which is less fast as compared to gzip but it makes more compact files than gzip. To compress the file using bzip2, you need to use below command.
To compress directory, you need to use -r option. It means zip files recursively. To uncompress any *.bz2 file, you can use below command.
$ bzip2 abc.txt
bzip2 -d <file-name>.bz2
Compressing file using xz commandxz compression uses LZMA2 algorithm. Remember that 7zip also uses the same algorithm. Below command can be used to compress file using xz utility
Below command can be used to list the details of compression
$ xz <file-name>
Below command can be used to uncompress the .xz file.
$ xz -l <file-name>.xz
$ xz -d <file-name>.xz
Archiving and Compressing using tar commandIn below example we are using tar command to archive and compress mybig-direcotry using basic algorithm. Here -c stands for create new archive and -x stands for extract compressed files. f stands for file.
In below example we are using tar command to archive and compress mybig-direcotry using gz algorithm.
$ tar -cvf mytarball.tar mybig-direcotry $ tar -xvf mytarball.tar
In below example we are using tar command to archive and compress mybig-direcotry using bz2 algorithm.
$ tar -czvf mytarball.tar.gz mybig-direcotry $ tar -xzvf mytarball.tar.gz
In below example we are using tar command to archive and compress mybig-direcotry using xz algorithm.
$ tar -cjvf mytarball.tar.bz2 mybig-direcotry $ tar -xjvf mytarball.tar.bz2
$ tar -cJvf mytarball.tar.xz mybig-direcotry $ tar -xJvf mytarball.tar.xz
Web development and Automation testing