Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare contents of two directories on remote server using unix

I am new to unix and need some help here. I have two directories present on two different server. both the directories contains the same files. Now i want to check if all files are in sync in both the directories. If files are not in sync then i want to display only name of those files. I am able to do it when directories are on same server. not able to figure out how to do this when directories are present on two different servers.

eg: server1 /abc/home/sample1/ server2 /abc/home/sample2/ 

here i want only files name to display when it not in sync.

Thanks in advance

like image 764
DSD Avatar asked Oct 16 '13 06:10

DSD


People also ask

How do I compare directories in UNIX?

Use the dircmp command to compare two directories specified by the Directory1 and Directory2 parameters and write information about their contents to standard output. First, the dircmp command compares the file names in each directory.

How do I compare the contents of two folders?

If you double-click on a folder, it will expand to reveal its contents. If you double-click on a file it will open a side by side comparison and will highlight the differences, if any, between the two files. Double-clicking a file will open both copies in a side by side view and will highlight any differences.

How do I compare two files on a different server in Linux?

diff (short for difference) is a simple and easy to use tool which analyzes two files and displays the differences in the files by comparing the files line by line. It prints the lines that are different.


1 Answers

You can use rsync with the -n flag to find out if the files are in sync, without actually doing a sync.

For example, from server1:

rsync -n -avrc /abc/home/sample1/* server2:/abc/home/sample2/ 

This will print the names of all files (recursive, with the -r flag) that differ between server1:/abc/home/sample1/ and server2:/abc/home/sample2/

rsync used parameters explanation

-n, --dry-run - perform a trial run with no changes made

-a, --archive - archive mode; equals -rlptgoD (no -H,-A,-X)

-v, --verbose - increase verbosity

-r, --recursive - recurse into directories

-c, --checksum - skip based on checksum, not mod-time & size

like image 104
kielni Avatar answered Oct 12 '22 13:10

kielni