July 2019
M T W T F S S
« Jun    
1234567
891011121314
15161718192021
22232425262728
293031  

Categories

WordPress Quotes

I've learned that you shouldn't go through life with a catcher's mitt on both hands; you need to be able to throw something back.
Maya Angelou
July 2019
M T W T F S S
« Jun    
1234567
891011121314
15161718192021
22232425262728
293031  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (36)
Ansibile (19)
Apache (134)
Asterisk (2)
cassandra (2)
Centos (211)
Centos RHEL 7 (267)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (30)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
health (1)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (7)
Ldap (5)
Linux (188)
Linux Commands (166)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (35)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (35)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (62)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

22 visitors online now
1 guests, 21 bots, 0 members

Hit Counter provided by dental implants orange county

GNU tar (Tape ARchive)

GNU tar (Tape ARchive) saves multiple files together into a single tape or disk archive, and can restore individual files from the archive. Here are some Linux tar Command with Useful Practical Examples

Some useful command line switches are given below, which are used in this article.

c => create an archive file.
v => show the detailed output ( or porgress ) of command.
x => extract an archive file.
f => filename of archive file.
z => Use archive through gzip.
t => viewing content of archive file.
j => Use archive through bzip2.
C => Use of define destination directory.
W => Verify a archive file.
Example 1: Create a .tar Archive File.

Below command will create an compressed ( tar ) file using all files and directories ( with subdirectories ) of /var/log directory.

# tar cvf rmohan-16-apr-2013.tar /var/log
Example 2: Create a .tar.gz Archive File.

Below command will create an gzip compressed ( tar.gz ) file using all files and directories ( with subdirectories ) of /var/log directory. I will create more compressed file than .tar file.

# tar czvf rmohan-16-apr-2013.tar.gz /var/log
Example 3: Create a .tar.bz2 Archive File.

This example is used for creating bz2 files. bz2 files are higher compressed than .tar and .tar.gz files. Its also take more time to compress than others.

# tar cjvf rmohan-16-apr-2013.tar.bz2 /var/log
Check difference between .tar , .tar.gz and .tar.bz2 file sizes.

# ls -l rmohan-16-apr-2013.tar*
-rw-r–r–. 1 root root 26818560 Apr 12 22:25 rmohan-16-apr-2013.tar
-rw-r–r–. 1 root root 697802 Apr 13 00:25 rmohan-16-apr-2013.tar.bz2
-rw-r–r–. 1 root root 1091399 Apr 13 00:26 rmohan-16-apr-2013.tar.gz
As per above output .tar.bz2 is higher compressed and .tar is lower compressed file.

Example 4: List content of .tar, .tar.gz, .tar.bz2 Archive File.

Some times we requried to list content of archive file without extracting them. Below example will help you to do it.

# tar -tvf rmohan-16-apr-2013.tar
# tar -tvf rmohan-16-apr-2013.tar.gz
# tar -tvf rmohan-16-apr-2013.tar.bz2
Example 5: Uncompress .tar Archive File.

To uncompress a .tar file use below command. It will extract all files and directories ( with subdirectories ) in current path. To uncompress in different location check Example 8.

# tar -xvf rmohan-16-apr-2013.tar
Example 6: Uncompress .tar.gz Archive File.

To uncompress a .tar.gz ( tar + gzip ) file use below command. It will extract all files and directories in current path.

# tar -xvf rmohan-16-apr-2013.tar
Example 7: Uncompress .tar.bz2 Archive File.

Use below example to uncompress a .tar.bz2 ( tar + bz2 ) file. It will extract all files and directories in current path.

# tar -xvf rmohan-16-apr-2013.tar
Example 8: Extract Archive in different location.

Use C command line switch to specify a location for extracting an archive file.

# tar xf rmohan-16-apr-2013.tar -C /Output/Dir/
Example 9: Verify .tar Archive Files.

To verify .tar file use ‘W’ switch with ‘t’. For you information .tar.gz and .tar.bz2 can not be verified using this. Use below command to verify your tar file.

# tar tvWf /root/rmohan-16-apr-2013.tar
Sample Output:

tar: This does not look like a tar archive
tar: Skipping to next header
tar: VERIFY FAILURE: 13 invalid headers detected
Verify -rw——- root/root 0 2013-03-31 03:50 var/log/spooler-20130407
Verify -rw——- root/utmp 384 2013-04-12 21:31 var/log/btmp
Verify -rw-r–r– root/root 211614 2013-03-18 19:20 var/log/dracut.log
Verify -rw——- root/root 5793 2013-04-12 22:20 var/log/secure
Verify -rw-r–r– root/root 4952 2013-04-01 14:40 var/log/krb5kdc.log-20130401
Verify drwxr-xr-x root/root 0 2011-12-08 06:00 var/log/spice-vdagentd/
Verify drwx—— root/root 0 2013-04-12 14:57 var/log/samba/
Verify -rw-r–r– root/root 0 2013-04-09 01:58 var/log/samba/log.192.168.1.199
Verify -rw-r–r– root/root 1972 2013-04-12 14:37 var/log/samba/log.nmbd
var/log/samba/log.nmbd: Mod time differs
var/log/samba/log.nmbd: Size differs
Verify -rw——- root/utmp 384 2013-03-18 20:26 var/log/btmp-20130401
Verify -rw-r–r– root/root 1382 2013-04-11 13:53 var/log/kadmind.log
Verify drwxrwx–T root/gdm 0 2013-04-11 13:53 var/log/gdm/
Verify -rw-r–r– root/root 0 2013-04-11 13:53 var/log/gdm/:0-slave.log
Verify -rw-r–r– gdm/gdm 1387 2013-04-05 17:07 var/log/gdm/:0-greeter.log.1
Verify -rw-r–r– root/root 18983 2013-03-25 14:10 var/log/gdm/:0.log.3
Verify -rw-r–r– root/root 19028 2013-04-05 17:06 var/log/gdm/:0.log.1
Verify -rw-r–r– root/root 18983 2013-03-22 15:42 var/log/gdm/:0.log.4
Verify -rw-r–r– root/root 98 2013-04-05 17:07 var/log/gdm/:0-slave.log.1
Verify -rw-r–r– root/root 18983 2013-04-11 13:53 var/log/gdm/:0.log
tar: Exiting with failure status due to previous errors
Due to long list of output, some of output has been hidden in above command output.

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam