Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...