Sponsored Content
Top Forums Shell Programming and Scripting How to differentiate two tar files Post 302304318 by Beast Of Bodmin on Monday 6th of April 2009 06:01:16 AM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 09:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy