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 individually:
$ zip -r file_name.zip files_dir

After running the preceding command, the file to be compressed or the directory to be compressed, such as files_zip will be compressed and you will get a compressed file called file_name.zip ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.