0% found this document useful (0 votes)
21 views6 pages

Archive and Compress Files and Directories in Linux

The document discusses archiving and compressing files in Linux. It explains that archiving combines files into one file while compression reduces file sizes. The tar command is used to archive files and directories into a .tar file. The gzip and bzip2 commands can be used to compress files into .gz or .bz2 files respectively, with bzip2 providing better compression but being slower. Lab work involves archiving and compressing the /var directory before copying to a mounted flash drive.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Archive and Compress Files and Directories in Linux

The document discusses archiving and compressing files in Linux. It explains that archiving combines files into one file while compression reduces file sizes. The tar command is used to archive files and directories into a .tar file. The gzip and bzip2 commands can be used to compress files into .gz or .bz2 files respectively, with bzip2 providing better compression but being slower. Lab work involves archiving and compressing the /var directory before copying to a mounted flash drive.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER

SYSTEM ENGINEERING - Linux Lab


EXPERIMENTE #5 Archive and compress files and directories in Linux

Pre Laboratory:
1. What are the differences between archiving and compression?
2. Write a command use to compress files?
3. Write a command use to archive directories?
4. What is the difference between tar and gzip in linux?
5. What is a mount in linux?

Objective:
1. Understand the concepts of archive, compress and how to perform it.
2. Learn archiving command in linux and apply it.
3. Learm compress command in linux and apply it.
4. Understand the benefits of mount command and apply it.

Introduction:
Archiving is the process of combining multiple files and directories (same or different sizes) into
one file. On the other hand, compression is the process of reducing the size of a file or directory.
Archiving is usually used as part of a system backup or when moving data from one system to
another.

Part 1: Archive files and directories using the tar command.


tar is a Unix command representative TAPE Archive (tape archive). It is used to combine or store
multiple files (same or different sizes) into one file. There are four main modes of operation in the
tar utility.
 c – Create an archive from a file or directory.
 x – Extract archive.
 r – Append file to archive.
 t - List the contents of the archive.

Create a new archive:


Syntax:

tar cf nam of archived directory.tar files/directories to be archived

Mr. Allam Abumwais Eng. Nour Kmail


ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER
SYSTEM ENGINEERING - Linux Lab
EXPERIMENTE #5 Archive and compress files and directories in Linux

Example:

 The c flag refers to the creation of a new archive, where f is the specified archive file.
You can use cvf instead of cf, so that v sets the screen output to get updates. As follows:

2|Page
ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER
SYSTEM ENGINEERING - Linux Lab
EXPERIMENTE #5 Archive and compress files and directories in Linux

Extract archive:
Extracting your archive in order to restore the files is easy: Just use xvf instead of cvf. That, in the
example, will save new copies of the original files and directories in the current location.

Example:

You can also have tar send your extracted files to some other place using the
-C argument, followed by the target location:
Example:

List archives without extracting them:


To list the contents of the archive, we use the t symbol.

3|Page
ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER
SYSTEM ENGINEERING - Linux Lab
EXPERIMENTE #5 Archive and compress files and directories in Linux

Add files to archive

Files or directories can use r symbol to Add / update to an existing archive.

Example:

Part 2: compress files and directories using the zip command.


Both Linux and UNIX include various commands for Compressing and decompresses (read as
expand compressed file). To compress files you can use gzip, bzip2 and zip commands. To expand
compressed file (decompresses) you can use and gzip -d, bunzip2 (bzip2 -d), unzip commands.
Compressing files:
 gzip command: gzip compress the size of the given files using Lempel-Ziv coding (LZ77).
Whenever possible, each file is replaced by one with the extension .gz.

Syntax
gzip {filename}

 bzip2 command: bzip2 compresses files using the Burrows-Wheeler block sorting text
compression algorithm, and Huffman coding. Compression is generally considerably better
than that achieved by bzip command (LZ77/LZ78-based compressors). Whenever
possible, each file is replaced by one with the extension .bz2.

Syntax
bzip2 {filename}

Example:

4|Page
ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER
SYSTEM ENGINEERING - Linux Lab
EXPERIMENTE #5 Archive and compress files and directories in Linux

So what is the best?


gzip is very fast and has small memory footprint. bzip2 has notably better compression
ratio than gzip, bzip2 creates about 15% smaller files than gzip.which has to be the reason
for the popularity of bzip2; it is slower than gzip especially in decompression and uses
more memory. However the memory requirements of bzip2 should be nowadays no
problem even on older hardware.

o Size of /bin/ file = 123MB


o The du command is a standard Linux/Unix command that allows a user to
gain disk usage information quickly.

5|Page
ARAB AMERICAN UNIVERSITY – FACULTY OF ENGINEERING & INFORMATION TECHNOLOGY – COMPUTER
SYSTEM ENGINEERING - Linux Lab
EXPERIMENTE #5 Archive and compress files and directories in Linux

Lab work Question????


 Use tar and compress command to archive and compress the contents of /var system file
and copy the result to flash memory mounted by directory in /home/user account.
 Discuss with your teacher all commands needed to accomplish this task...
 Not that this task need to mount flash memory using mount command.
 Discuss the mount command with your teacher.

6|Page

You might also like