21MCA2234 Linux Worksheet 2.2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Student Name: Vishu Raman UID: 21MCA2234

Branch: MCA Section/Group: MCA2/A


Semester: 1st Date of Performance: 15/11/21
Subject Name: Linux Administration Lab Subject Code: 21CAP-608

Aim- To compress and backup files using compression and archiving commands respectively.
Task to be done-
1. You wish to restore the file named ABC.txt which was backed up in the tarfile with name
MyBackup.tar. What command should you type? Use an option of gzip command to
compress a tar file MyBackup.tar. Now create a file with name MyBackUp.tar and then
try to search a file named MyBackup.tar using regular expressions after executing listing
command.

2. Create a file named try.txt and write about yourself in about 20 lines. Now check the size
of the file. Reduce the size of this file using zip and also add a comment to zipfile also.
After compression, check the size of file again.

Concept Used-
Compression and Archiving commands
Synta Description Example(
x s)
gzip {filename} Gzip compress the size of gzip
the given files using mydata.doc
Lempel-Ziv coding (LZ77). gzip *.jpg
Whenever possible, each
file is replaced by
one with the extension .gz.
bzip2 {filename} bzip2 compresses files using bzip2
the Burrows-Wheeler block mydata.doc
sorting text compression bzip2 *.jpg
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.
zip {.zip-filename} zip is a compression and file zip mydata.zip
{filename-to- compress} packaging utility for mydata.doc zip
Unix/Linux. Each file is data.zip *.doc
stored in single .zip
{.zip-filename} file
with the extension .zip.
tar -zcvf {.tgz-file} The GNU tar is archiving tar -zcvf data.tgz *.doc
{files} tar -jcvf {.tbz2- utility but it can be use to tar -zcvf pics.tar.gz *.jpg
file} {files} compressing large file(s). *.png tar -jcvf data.tbz2
GNU tar supports both *.doc
archive compressing through
gzip and bzip2. If you have
more than 2 files then it is
recommended to use tar
instead of gzip or bzip2.
-z: use gzip compress
-j: use bzip2 compress

Decompressing and Unarchiving commands

Synta Description Example(


x s)
gzip -d {.gz Decompressed a file that is gzip -d
file} gunzip created using gzip mydata.doc.gz
{.gz file} command. File is restored to gunzip
their original form mydata.doc.gz
using this command.
bzip2 -d {.bz2- Decompressed a file that is bzip2 -d
file} bunzip2 created using bzip2 mydata.doc.bz2
{.bz2-file} command. gunzip
File is restored to their mydata.doc.bz2
original form using this
command.
unzip {.zip file} Extract compressed files in unzip file.zip
a ZIP archive. unzip data.zip resume.doc
tar -zxvf {.tgz- Untar or decompressed a tar -zxvf data.tgz
file} tar -jxvf file(s) that is created tar -zxvf pics.tar.gz
{.tbz2-file} using tar compressing *.jpg tar -jxvf
through gzip and bzip2 data.tbz2
filter

Listing files in compressed and archived files.

Synta Description Example(


x s)
gzip -l {.gz file} List files from a GZIP archive gzip -l mydata.doc.gz
unzip -l {.zip file} List files from a ZIP archive unzip -l mydata.zip
tar -ztvf {.tar.gz} List files from a TAR archive tar -ztvf pics.tar.gz
tar -jtvf {.tbz2} tar -jtvf data.tbz2
Steps:
1.
i. creating MyBackup.tar with ABC.txt
$cat > ABC.txt
Hello this is ABC.txt
$tar -cvf MyBackup.tar ABC.txt
ii. unarchiving MyBackup using tar command with -x option
$tar -xvf MyBackup.tar
iii.compressing MyBackup.tar using gzip command
$gzip MyBackup.tar
iv.creating file MyBackUp.tar

$tar -cvf MyBackUp.tar ABC.txt


v.searching MyBackup.tar using regular expression
$ls | grep “MyBackup.tar”

2.
i. creating try.txt and adding 20 lines
$vi try.txt
ii. checking size of try.txt file
$ls -lh
iii.compressing try.txt using zip command with comment
$zip -c try.zip try.txt

iv. checking file size after compression


$ls -lh
Result:

1.

Figure 1.1

Figure 1.2

Figure 1.3

Figure 1.4
Figure 1.5
2.

Figure 2.1

Figure 2.2

Figure 2.3
Figure 2.4

Learning Outcomes:
1. Compressing files using zip,gzip,bzip2 commands
2. Decompressing files.
3. Archiving files using tar command.
4. Archiving and compressing files.
5. Unarchiving files.

Evaluation Grid:
Sr. Parameters Marks Maximum
No. Obtained Marks
1. Worksheet 10
2. Demonstration/Performance 5
/Pre Lab Quiz
3. Post Lab Quiz 5

You might also like