Archive and Compress Files and Directories in Linux
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.
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:
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
Example:
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
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
6|Page