Abhi Exp.10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Experiment no.

10

Date:

Backup and restore

Aim: File compressing mechanisam using tar Gzip and gunzip.

Procedure:

File compression helps to reduce file size and share files efficiently. And compressed
files are also easier to copy to remote servers. Also compress older and rarely used
files and save them for future use which helps you conserve disk space.

tar

The tar command is used to create an archive, grouping multiple files in a single file.Its
name comes from the past and means tape archive.

Syntax

tar [flags] destinationFileName sourceFileNames

This command creates an archive named archive.tar with the content of file1 and file2:

tar -cvf archive.tar file1 file2

c stands for create. The f option is used to write to file the archive. The v is providing
details of the files that have been archived.

 To remove the original files after creating an archive, use the –remove-files flag.

tar -cvf archive.tar * --remove-files


 list the files contained in an archive:

tar -tf archive.tar

t flag stands for viewing the contents of the archive

 To find a particular file inside the archive

Tar -tvf archive.tar filename

 To extract files from an archive in the current folder, use:

Tar -xvf archive.tar

The x option stands for extract

 To extract them to a specific directory, use:

Tar -xf archive.tar -C directory

 Tar is often used to create a compressed archive, gzipping the archive. This is
done using the z option:

Tar -czf archive.tar.gz file1 file2


This is just like creating a tar archive, and then running gzip on it.

 To extract files from a compressed archive in the current folder, use:

Tar -xzvf archive.tar.gz

-z specifies that the archive is gzip.

 To unarchive a gzipped archive, use gunzip , or gzip -d , and then unarchive it,
but tar -xf will recognize it’s a gzipped archive

Tar -xf archive.tar.gz

 To Delete files from the archive, use the –delete option

Tar –delete -f archive.tar file_name


Gzip

Gzip (GNU zip) is a compressing tool, which is used to truncate the file size. By default
original file will be replaced by the compressed file ending with extension (.gz).

 compress a file using the gzip compression protocol using the gzip command.

Gzip filename

 This will compress the file, and append a .gz extension to it. The original file is
deleted.

To prevent deleting files, you can use the -c option and use output redirection to
write the output to the filename.gz file:

Gzip -c filename > filename.gz

or

Use -k (keep) option:

Gzip -k filename

There are various levels of compression. The more the compression, the longer it will
take to compress (and decompress). Levels range from 1 (fastest, worst compression)
to 9 (slowest, better compression), and the default is 6.

choose a specific level with the -<NUMBER> option:

Gzip -1 filename

 compress multiple files by listing them


Gzip filename1 filename2

 compress all the files in a directory, recursively, using the -r option:

Gzip -r a_folder

 The -v option prints the compression percentage information. Example to used


along with the -k option:

Gzip -kv wget-log

 Gzip can also be used to decompress a file, using the -d option:

Gzip -d filename.gz

 The compression ratio or how much the original file has compressed, use -l
option Gzip -l filename.gz
Gunzip

The gunzip command is basically equivalent to the gzip command, except the -d option
is always enabled by default.

 The command can be invoked in this way:

Gunzip filename.gz

This will gunzip and will remove the .gz extension, putting the result in the

filename file.

 If that file exists, it will overwrite that.

Extract to a different filename using output redirection using the -c option:

Gunzip -c filename.gz > anotherfilename

 To keep both the compressed and

decompressed file

Gunzip -k filename.gz
 To recursively decompresses all files in a given directory, use the -r option:

Gunzip -r directory

 List the Compressed File Contents, use the -l option

Gunzip -l filename.gz

Result: Successfully executed File compressing mechanisam using tar Gzip and gunzip.

You might also like