The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Differentiate Soft and Hard Link balu_solaris UNIX for Dummies Questions & Answers 4 01-23-2009 05:18 PM
how to differentiate columns of a file in perl with no specific delimiter Amiya Rath Shell Programming and Scripting 9 07-15-2008 12:51 AM
differentiate between a file and a device keith_hampson UNIX for Dummies Questions & Answers 6 06-01-2008 02:47 PM
how to differentiate a file from a folder in a FIND? denysQC UNIX for Dummies Questions & Answers 3 06-06-2006 06:02 PM
How to Differentiate Between Files and Folders? dgower2 UNIX for Dummies Questions & Answers 6 04-28-2006 12:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2009
siri_14 siri_14 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 6
Question How to differentiate two tar files

Hi All,
I am new to this unix stuff.I just have one doubt:suppose i have two tar files and sometimes it happens that when we just check these files from outside these two tar files look same
Code:
 
"Eg:
ls -lrt
drw-r--r--   1 oasis    logadmin   37067 Apr  3 05:48 file1.tar
drw-r--r--   1 oasis    logadmin   37067 Apr  3 05:48 file2.tar"
but when we check inside that we may find there are some jars which have been changed.Now i want to have one script which will compare these two tars and then provide as output those jars inside these two tars which have been changed.Pardon me for any grammatical mistakes.

Thanks in advance
  #2 (permalink)  
Old 04-03-2009
amitranjansahu's Avatar
amitranjansahu amitranjansahu is offline
Registered User
  
 

Join Date: Jan 2009
Location: Gurgaon,INDIA
Posts: 239
user tar -vft tarfile to see the content and size of the file
  #3 (permalink)  
Old 04-07-2009
mr.perffect mr.perffect is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Quote:
Originally Posted by amitranjansahu View Post
user tar -vft tarfile to see the content and size of the file
expanding on this why not send stdout to file ...

tar -vft tarfile1 > file1
tar -vft tarfile2 > file2

then

diff file1 file2
  #4 (permalink)  
Old 04-04-2009
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
you can use cksum command to see if the checksum of the tar files are same. But for identifying the changed files, you have to extract the tar(tar -xvf) and compare the files.
  #5 (permalink)  
Old 04-06-2009
siri_14 siri_14 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 6
Hi all,
Thanks for your replies.
As i am a newbie to scripting i am not sure how to proceed.I am looking for a script that differentiates between two tar files without extracting(due to space issues) and output the files that have been changed.Please note that these tar files will contain jar files and inside those there are files.
The structure is :
tarfile :it is an external directory inside that there are jars which are also directories.and inside that there are files.and i have to differentiate between such two tarfiles that wich all files have been changed inside that.it is not always necessary that there is a difference between two tarfiles.It may happen that nothing has changed.
I work in java and javascript and am not so comfortable with unix.So requesting your help.
Thanks in advance.
  #6 (permalink)  
Old 04-06-2009
Beast Of Bodmin Beast Of Bodmin is offline
Registered User
  
 

Join Date: Apr 2009
Location: Zurich
Posts: 9
Quote:
Originally Posted by siri_14 View Post
As i am a newbie to scripting i am not sure how to proceed.I am looking for a script that differentiates between two tar files without extracting(due to space issues) and output the files that have been changed.Please note that these tar files will contain jar files and inside those there are files.
In general, it is not possible to know which file has changed by looking at the size of the file or the time stamp.

In general, the command

Code:
cmp
will report the byte at which the first difference is found.

Code:
sum
or (better)

Code:
md5sum
are statistically highly likely to work. Well, the chances of md5sum reporting the same hash value for two different files is vanishingly low, but cmp is probably faster.

So you should begin by determining if the files are indeed different

Code:
cmp file1.tar file2.tar
file1.tar file2.tar differ: differ: char 6, line 1
If they are, you should next compare the table of contents:

Code:
tar tf file1.tar >/tmp/file1.toc
tar tf file2.tar >/tmp/file2.toc
cmp /tmp/file1.toc /tmp/file2.toc
If the TOCs differ, then use sdiff

Code:
sdiff /tmp/file1.toc /tmp/file2.toc
If the TOC does not differ, you will need to extract the files from the two .tar files, one by one, and cmp these extracted files.

Code:
[ ! -d /tmp/file1 ] && mkdir /tmp/file1
[ ! -d /tmp/file2 ] && mkdir /tmp/file2
tar tf file1.tar >/tmp/file1/file1.toc
tar tf file2.tar >/tmp/file2/file2.toc
for f in $(cat /tmp/file1/file1.toc)
do
   cd /tmp/file1
   tar xf /path/to/file1.tar $f
   cd /tmp/file2
   tar xf /path/to/file2.tar $f
   Echo comparing  /tmp/file1/$f  /tmp/file2/$f
   cmp /tmp/file1/$f /tmp/file2/$f
done
  #7 (permalink)  
Old 04-06-2009
reddybs reddybs is offline
Registered User
  
 

Join Date: Jan 2009
Location: Sriharikota-AP-India
Posts: 53
#d vfg3

Last edited by reddybs; 04-06-2009 at 06:52 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0