Book Image

Bash Cookbook

By : Ron Brash, Ganesh Sanjiv Naik
Book Image

Bash Cookbook

By: Ron Brash, Ganesh Sanjiv Naik

Overview of this book

In Linux, one of the most commonly used and most powerful tools is the Bash shell. With its collection of engaging recipes, Bash Cookbook takes you through a series of exercises designed to teach you how to effectively use the Bash shell in order to create and execute your own scripts. The book starts by introducing you to the basics of using the Bash shell, also teaching you the fundamentals of generating any input from a command. With the help of a number of exercises, you will get to grips with the automation of daily tasks for sysadmins and power users. Once you have a hands-on understanding of the subject, you will move on to exploring more advanced projects that can solve real-world problems comprehensively on a Linux system. In addition to this, you will discover projects such as creating an application with a menu, beginning scripts on startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated Secure Shell (SSH) keys. By the end of this book, you will have gained significant experience of solving real-world problems, from automating routine tasks to managing your systems and creating your own scripts.
Table of Contents (15 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Compressing and archiving files


There is a difference between a compressed and an archive file. So, what is an archive file? It is a collection of files and directories that are stored in a single file. An archive file is not a compressed file.

What is a compressed file? This is a collection of files and directories stored in one file. It uses less disk space for storage.

 

In this section, we are going to discuss two compression tools:

  • bzip2
  • zip

Getting ready

You should have files to archive and compress.

How to do it...

First, let's see how we can compress the files:

  1. We are going to look at compression with the help of bzip2. Decide which file to compress and run the following command:
$ bzip2 filename

Using bzip2, we can compress multiple files and directories at the same time. Just separate them by putting a space between each of them. You can compress it as follows:

$ bzip2 file1 file2 file3 /student/work
  1. We are going to use zip for compression. By using the zip compression tool, files are compressed...