Visit Our UNIX and Linux User Community

UNIX utility to find difference in folder, file and contents of file against a base version

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX utility to find difference in folder, file and contents of file against a base version
# 1  
Old 11-17-2016
UNIX utility to find difference in folder, file and contents of file against a base version

I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility?

Thanks, Sripathi
# 2  
Old 11-17-2016

I'd start with cmptree, from the following list of possibilities.
cmptree Compare directory trees recursively and report the differences. (what)
Path    : ~/bin/cmptree
Length  : 183 lines
Type    : Bourne-Again shell script, ASCII text executable
Shebang : #!/bin/bash

Difference, similarity, compare

        1) diff, standard

        2) cmp, standard

        3) dwdiff, cdif (local), word differences

        4) cmptree (local), dirdiff (GUI), compare directory trees

        5) docdiff, compare by character, word, line, numerous output formats

        6) meld (GUI), diff and merge files

        7) numdiff, my-ndiff (local), snd (local), compare numerically

        8) comm, standard, compare 2 sorted files, 3 column output

        9) comm-split (local), compare like comm, but split output to
           separate files.

        10) multi-comm (local), compare n files, need not be sorted

        11) contrast (local), like comm, needs no sort, symmetric and
        simple differences, intersection, union

        12), perl work-alike for diff

        13) multi-diff (local), common lines, multiple files, re-write omitting common lines

        14) psame (local), find similarity between 2 text files

        15) fdupes, rdfind, duff, find duplicate files

        16) dateutils.ddiff, find difference in dates, times

In this environment:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie)

Best wishes ... cheers, drl
# 3  
Old 11-17-2016
You can also have a look at the diff command. Files only in one directory tree will be marked in Only in ..... messages, so you could select those from all your output perhaps:-
diff dir1 dir2 | egrep -v '^Only in'

An alternate might be to find all files in the directories and get the checksums into a pair of files, which you can then use diff against, something like:-
cd dir1
find . -type f -exec sum {} \; | sort > /tmp/dir1.sums

cd dir2
find . -type f -exec sum {} \; | sort > /tmp/dir2.sums

diff /tmp/dir[12].sums

This will list out different checksums and files in only one of the directories. It depends what you want.

Do either of these help?


Last edited by rbatte1; 11-25-2016 at 05:27 AM.. Reason: Correcting an error
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 11-17-2016

See post #9 at thread find same size file for demonstrations of fdupes and rdfind.

Best wishes ... cheers, drl

Last edited by drl; 11-18-2016 at 01:07 PM.. Reason: Edit 1: minor typo
This User Gave Thanks to drl For This Post:
# 5  
Old 11-24-2016
@drl, I tried following the links to cmptree, but it seems that it is no longer available. Can you post a listing?
# 6  
Old 11-24-2016
It is no longer required by the standards, but many systems still have a dircmp utility that can be used to compare the file hierarchies rooted in two directories looking for added, missing, and common files and (for files that are present in both hierarchies) it can also provide a diff listing for differences between those files.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 11-24-2016
Hi, jgt .

For The Shell Corner: cmptree | Dr Dobb's ,about half-way down the page, starts with:
# cmptree: compare directory trees recursively and report the differences.
# Author: Ives Aerts

Once you get cmptree working, it can be a useful addition to one's toolbox because you can take it with you.

I do recall dircmp now that Don mentioned it. I found a source for dircmp at: Shell dircmp / Code /
-- however I have not tried it.

As Robin noted, modern diff can compare directories.

Thanks @Robin @Don, I have modified my diff list accordingly.

Best wishes ... cheers, drl

Last edited by drl; 11-24-2016 at 04:09 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #890
Difficulty: Easy
In sed, the REGEX dot (.) matches exactly one character.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk code to find difference in second file which is not present in first file .

Hi All, I want to find difference between two files and output only lines which are not present in second file .I am using awk and I am getting only the first difference but I want to get all the lines which are not present in file2 .Below is the code I am using . Please help to get the desired... (7 Replies)
Discussion started by: srinivasrao
7 Replies

2. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

How to copy all the contents of a list of files present in a folder to a particular file?

Hi All, I want to copy all the contents of a list of files in a folder to a particular file. i am using following command: cat dir/* >> newFile.txtIt's not working. Could you please help? Thanks, Pranav (3 Replies)
Discussion started by: Pranav Bhasker
3 Replies

4. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, etc.. the files names as well as contents should be changes to AK9-Create.xml, etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

5. UNIX for Dummies Questions & Answers

find lines in another file based on contents in a second file

Hello, I have a file with tab delimited columns like: File1 A 2 C R F 4 D Q C 9 A B ...... I want to grep out the lines in a second file, File2, corresponding to each line in File1 Can I do this: while read a b c d do grep '$a\t$b\t$c\t$d' File2 >>... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

6. UNIX for Dummies Questions & Answers

Help with folder and file difference

Hello, I was wondering how to make difference between file and folder while using ls -l? I see it on the output because "d" is for dir and "-" for file, but how to make this input to other command? Because I am trying to bzip2 if it's the file and tar if it's a directory. (9 Replies)
Discussion started by: juzt1s
9 Replies

7. Shell Programming and Scripting

Search through subfolders and move them into separate folder on the base of file size

Hello guys I am sure that you will help me on this issue as you did earlier::) Scenario : I have a folder named "XYZ". It consist many sub-folders and subfolder contain severals files. there may be abc.dat in each subfolder. Now i want to seperate subfolders on follwing conditions- if abc.dat... (12 Replies)
Discussion started by: infiant
12 Replies

8. UNIX for Dummies Questions & Answers

Disk Usage in GB and Unix command to find the biggest file/folder

Hi All, Please help me out 1) Command to find the disk usage in GB. I know that du -k will give in kilobites. 2) How to find the Biggest file/folder in a given set of files/folders. Thanks in advance Regards, Manas (8 Replies)
Discussion started by: manas6
8 Replies

9. HP-UX

how to redirect the growing contents of log file to another file in unix

how to redirect the growing contents of log file to another file in unix (2 Replies)
Discussion started by: megh
2 Replies

10. UNIX for Dummies Questions & Answers

How to compare the difference between a file and a folder??

Hi, I have a .txt file which has to be compared with a folder and print the difference to some other .txt file. I did try with the diff command..i mean diff /tmp/aaa/bbb.txt /space/aaa/bbb/ /***bbb.txt contains all the files names which may or may not exist in the folder i need... (2 Replies)
Discussion started by: kumarsaravana_s
2 Replies

Featured Tech Videos