Tuesday, July 21, 2015

Day 22: The Linux Command Line Ch18 Notes


Chapter 18 - Archive and Backup

Commands:

Compressing Programs:

gzip - Compress or expand files.
bzip2 - A block sorting file compressor.

the archiving programs:

tar - Tape-archiving utility.
zip - Package and compress files.

and the file synchronization program:

rsync - Remote file and directory synchronization.


Lab 12

  1. List the /etc directory content and redirect output to foo.txt file. Check the size of the file.
  2. Compress foo.txt file and check its size after compression. Use gzip. Then decompress the file.
  3. Compress the file using bzip2 utility and check the file size.
  4. Decompress the file.
  5. Use foo.txt to create an archive that is going to be compressed at the same time (foo.tar.gz). Use: Verbose option.
  6. You are about to send a file to Window user. How would you compress/decompres it?
  7. There is an external disk mounted in /media/jaro directory. Its name is Seagate Expansion Drive. Crate a 'backup' directory on it and store a directory on it (my case 'Books').

Lab 12 Solutions

List the /etc directory content and redirect output to foo.txt file. Check the size of the file.

pi@raspberrypi ~ $ ls /etc > foo.txt; ls -l foo*
-rw-r--r-- 1 pi pi 1798 Jul 21 09:22 foo.txt
pi@raspberrypi ~ $ 

Compress foo.txt file and check its size after compression. Use gzip. Then decompress the file.

pi@raspberrypi ~ $ gzip foo.txt; ls -l foo*
-rw-r--r-- 1 pi pi 910 Jul 21 09:22 foo.txt.gz

pi@raspberrypi ~ $

pi@raspberrypi ~ $ gunzip foo.txt.gz

Compress the file using bzip2 utility and check the file size.

Decompress the file.

pi@raspberrypi ~ $ bzip2 foo.txt ; ls -l foo*
-rw-r--r-- 1 pi pi 1001 Jul 21 09:22 foo.txt.bz2

pi@raspberrypi ~ $

pi@raspberrypi ~ $ bunzip2 foo.txt.bz2 

pi@raspberrypi ~ $ 

Use foo.txt to create an archive that is going to be compressed at the same time (foo.tar.gz). Use: Verbose option.

pi@raspberrypi ~ $ tar -czvf foo.tar.gz foo.txt; ls -l foo*.gz
foo.txt
-rw-r--r-- 1 pi pi 1025 Jul 21 09:38 foo.tar.gz

pi@raspberrypi ~ $

You are about to send a file to Window user. How would you compress/decompress it?

$ zip file/unzip file
$ zip -r directory/unzip directory

There is an external disk mounted in /media/jaro directory. Its name is Seagate Expansion Drive. Crate a 'backup' directory on it and store a directory on it (my case 'Books').

Notice!
The name of a drive contains spaces. You can use quotes or backslashes to enter that disk.

cd /media/jaro/Seagate\ Expansion\ Drive/
rsync -av Books/ /media/jaro/Seagate\ Expansion\ Drive/Backup