How to differentiate two tar files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to differentiate two tar files
# 1  
Old 04-03-2009
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.Smilie

Thanks in advance
# 2  
Old 04-03-2009
user tar -vft tarfile to see the content and size of the file
# 3  
Old 04-04-2009
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.
# 4  
Old 04-06-2009
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.
# 5  
Old 04-06-2009
Quote:
Originally Posted by siri_14
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

# 6  
Old 04-06-2009
#d vfg3

Last edited by reddybs; 04-06-2009 at 07:52 AM..
# 7  
Old 04-06-2009
@siri,

Just do diff b/w the two tar files.

diff -ibw file1.tar file2.tar
O/P: Binary files file1.tar and file2.tar differ.
But it will not show the difference.

cmp file1.tar file2.tar
The cmp result show differ in byte number, line number
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Differentiate 2 files name

Hello All, I have 2 Type of files. 1. MYTEST001_RKP_DORALDO_20150402120000.zip 2. CMP001_STD001_MOGANO_RPSL_20150409_C.zip I can receive these Two type of file at one location. If i receive second type of file CMP001_STD001_MOGANO_RPSL_20150409_C.zip I have to process without... (9 Replies)
Discussion started by: yadavricky
9 Replies

2. Shell Programming and Scripting

Compare and Differentiate Multiple Files

Im using code below comparing and getting the diff of two files. But what about multiple files? can you help me guys diff -u file1 file2|sed -n '/^---/!{/^-/s/-//p}' diff -ui file1 file2| sed -n '/^++/!{/^+/s/+//p}' Example File1: aaa bbb ccc ddd File2: bbb eee (5 Replies)
Discussion started by: kenshinhimura
5 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. UNIX and Linux Applications

Differentiate between MS Word and Excel files in Unix

Hi, I want to differentiate between a MS Word and Excel file in Unix (not by extension). The condition which we are currently checking for is the pattern "\320\317\021\340" within first 40 bytes of the file. However this format is same in all MS Office files. Can somebody tell me any special... (4 Replies)
Discussion started by: phatak_rajan
4 Replies

6. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

7. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

8. UNIX for Dummies Questions & Answers

.tar.tar files

I downloaded what I thought was a gziped file (at least on remote server it had a .gz extention) and once I had it it was filename.tar.tar..I tried the standard untar tar -xvf filename on it and get an error. Does anyone know what's going on? (5 Replies)
Discussion started by: capeme
5 Replies

9. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies

10. UNIX for Dummies Questions & Answers

How to Differentiate Between Files and Folders?

Hi All, I'm a rookie using HPUX and I know this is going to sound like a bonehead question, but when I list the contents of a directory, how can I determine which objects are files and which are folders? I'm using the ll and ls commands to lists the contents. So far I've been determining the... (6 Replies)
Discussion started by: dgower2
6 Replies
Login or Register to Ask a Question