Module – 2.2 Linux understand & use Essential Tools – Part 2

4. tar

The Linux “tar” stands for tape archive, which is used by large number of Linux/Unix system administrators to deal with tape drives backup.

The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.

The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to anther disk or machine to machine.

1. To create a “TAR” backup of all files & folders under /home/sam/**

# cd /home/sam/

# tar -cvf sam.tar .  (dot at the end is  represent all files/folders in current directory )

or tar -cvf sam.tar /home/same

Here:

  1. c – Creates a new .tar archive file.
  2. v – Verbosely show the .tar file progress.
  3. f – File name type of the archive file.

2. To extract the “TAR” file

# tar -xvf sam.tar

3. To list the content on TAR file

# tar -tvf sam.tar

4. To create /extract TAR file with compression (gzip or bzip2)

gzip vs bzip2:

bzip2 takes more time to compress and decompress than gzip. bzip2 archival size is less than gzip.

# tar -cvfj archive_name.tar.bz2 /home/sam/

# tar -cvzf archive_name.tar.gz /home/sam/

tar cvzf archive_name.tar.gz dirname/

or untar the gzip file

# tar -xvfz archive_name.tar.gz5. Compress & Un-compress files with out TAR:

To compress a file, type:

# gzip file

# bzip2 file

To uncompress a file, type:

# gunzip file.gz

# bunzip2 file.bz2

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>