Linux-Basics-Complete-Course-With-Notes-Slides

File Compression and Archival

In this section, we will take a look to compress and archive files

Viewing file sizes

The du command, which stands for disk usage is a popular command to inspect the size of the file.

Archiving Files

Let us know take a look at widely used utility called tar

To archive a file or directory. Use tar command followed by -c to create an archive and the -f is used to specify the name of the tar file to be created. These is followed by files or directories to be archive.

$ tar -cf test.tar file1 file2 file3 
$ ls -ltr test.tar

The tar command followed by -tf option followed by the tar filename is used to see the contents of the tarball.

$ tar -tf test.tar

The tar command followed by -xf option followed by the tar filename is used to extract the contents from the tarball.

$ tar -xf test.tar

The tar command followed by -zcf option is used to compress the tarball to reduce its size.

$ tar -zcf test.tar

Compression

Compression is the technique used to reduce the size consumed by a file or a dataset.

The space of the compressed files created by these three commands depends on a few factors, such as the type of data being compressed, the other factors that effect the size are the compression algorithm used by these commands and the compression level used.

Compressed files need not to be uncompressed everytime