GETTING STARTED
WITH
COMPRESSION & ARCHIVING
LINUX & SCRIPTING
Mr. RAM
FILE COMPRESSION & ARCHIVING:
It is useful to store a group of files in one file for easy backup, for transfer to
another directory, or for transfer to another computer.
It is also useful to compress large files; compressed files take up less disk
space and download faster via the Internet.
COMPRESSED FILE:
A compressed file is a collection of files and directories that are stored in
one file and stored in a way that uses less disk space than all the individual
files and directories combined.
Red Hat provides the following tools for compression.
NOTE: Create one large file and apply the tools.
BZIP2:
To compress a file using bzipb2. The file will be saved as
filename.bz2.
$bzip2 filename
$ls -l filename.bz2
To uncompress a compressed file:
$bunzip2 filename.bz2
You can bzip2 multiple files and directories at the same time by
listing them with a space between each one:
$bzip2 filename.bz2 file1 file2 file3 dir1
$ls -l filename.bz2
LINUX & SCRIPTING
Mr. RAM
GZIP:
To compress a file using gzip. The file will be saved as [Link].
$gzip filename
$ls -l [Link]
To uncompress a compressed file:
$gunzip [Link]
To gzip multiple files and directories at the same time by listing them
with a space between each one:
$gzip [Link] file1 file2 file3 dir1
To compress a file with zip:
$zip [Link] filename
To uncompress a compressed file:
$unzip [Link]
To zip multiple files and directories at the same time by listing them
with a space between each one:
$zip -r [Link] file1 file2 file3 dir1
$ls -l [Link]
ARCHIVING FILES:
An archive file is a collection of files and directories stored in one file.
The archive file is not compressed - it uses the same amount of disk space as
all the individual files and directories combined.
NOTE: An archive file is not compressed, but a compressed file can be an
archive file.
TAR (TAPE ARCHIVE):
A TAR file is a collection of several files and directories in one file.
This is good way to create backups and archives.
LINUX & SCRIPTING
Mr. RAM
SYNTAX: $tar [options] [archive-file] [file / directories to be archived]
-c : create a new archive.
-f : File names.
-t : show the list of files in the tar file.
-v : show the progress of the files being archived.
-r : Append files to the end of an archive
-x : extract files from an archive.
-z : compress the tar file with gzip.
-j : compress the tar file with bzip2.
To create a tar file:
$tar -cvf [Link] file1 file2 dir1 dir2
$ls -l [Link]
To list the contents of a tar file:
$tar -tvf [Link]
Appending a file to [Link] file:
$tar -rvf [Link] filename
To extract the contents of a tar file:
$tar -xvf [Link]
To extract files in specific location:
$tar -xvf [Link] -C /opt $ls /opt
To create a tarred and bzipped compressed file, use the -j option:
$tar -cjvf [Link].bzip2 file1 file2 dir1 dir2
To create a tarred and gunzipped compressed file, use the -z option:
$tar -czvf [Link] file1 file2 dir1 dir2
$ls -l backup*