System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Comparing two directories

 
Regular Advisor

Comparing two directories

Can some one please tell me how to compare two directories in Linux when one of the directories is remote?
9 REPLIES 9
Honored Contributor

Re: Comparing two directories

Define "remote".

What kind(s) of access do you have to the
"remote" system?
Honored Contributor

Re: Comparing two directories

What do you want to compare in the directories? Do you want to compare the list of files in each directory? Or do you want to compare the contents of each file in the 2 directories?

A better definition of what you want is needed.
Regular Advisor

Re: Comparing two directories

Actually list of files in each directory and I want to know what files are missing.
Acclaimed Contributor

Re: Comparing two directories

Hi Wagar:

The same answer to your same question in HP-UX applies: See the 'diff' and 'comm' manpages.

Regards!

...JRF...
Frequent Advisor

Re: Comparing two directories

There are tools out there to do it, but if you like doing it yourself...

You could create two temp files, first a listing of the local dir and second a listing of the remote dir, and then compare the two suing used 'diff'.

Or if you only want to show what file(s) are missing, perhaps just use 'rsync' with the -n, --dry-run to show what would have been transferred.
Esteemed Contributor

Re: Comparing two directories

i will use here diff command if i want to compare files /directory.
Acclaimed Contributor

Re: Comparing two directories

Honored Contributor

Re: Comparing two directories

The rsync command can do a good job of comparing and reporting differences.
Its primary job is copying files between systems.
But you can run it as an itemized dry run.
That will just find and report the necessary copying and deletions to make one directory match another one.
It will compare file's checksums and can be asked to compare permissions.

$ rsync -a --dry-run -i -p --del trial/ sys2:trial
.d..t...... D1/
*deleting D1/F2
.d..t...... D2/

Be very careful to use --dry-run unless you actually want to modify one directory to match the other.
Trusted Contributor

Re: Comparing two directories

But be aware the the r* commands (remote commands) are not accepted in all business situations due to the lower security they provide.

It might be wise to include your commands into a ssh command.