Comparing two directories with diff


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two directories with diff
# 1  
Old 01-10-2019
Comparing two directories with diff

Hi all,

I have 2 directories on two different servers. I am trying to find out what is missing from directory X and what is missing from directory Y. they should both have the same exact files in them.

I understand some files may be missing from both directories on each server. I am not sure how to approach this. I already did an ls of each directory to a text file, now I just need to compare and filter. Is there an easy way I can do this with 'diff' or do I need to take another approach?

Thanks in advance
# 2  
Old 01-10-2019
Be lazy.
Create a new directory Z. Copy all the files in X to Z and all the files in Y to Z then copy Z over top of X and Y. After that, you have to compare the list of files to your master list to find any files that were missing in both.
# 3  
Old 01-10-2019
I was thinking of doing that too, by far the easiest way.

i have some concerns about doing this in a production system though..But the differences in the files will still be in the thousands, so a script will probably still be required.. Thanks for the advice.
# 4  
Old 01-10-2019
Is it the goal to know if there are missing files, or to keep the files in sync?

For the latter, I recommend rsync, which copies only missing files.
# 5  
Old 01-10-2019
Are the files text or binary (executables)?
# 6  
Old 01-10-2019
they are - data or International Language text
# 7  
Old 01-10-2019
Do you want to know about different contents too or is it enough if files with the right names exist.

For the latter(just an idea, not tested)

Code:
user@server1 $ ls >files-s1
user@server2 $ ls >files-s2
# create all files list
cat files-s1 files-s2 | sort -u >files-all

# missing from server1
grep -f files-s1 -v files-all

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with create multiple directories under diff file systems

Hi, Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl. ../ORCL_data01/oradata/orcl/data. ../ORCL_data01/oradata/orcl/redo. Script :- ========= for dir in `ls -d... (8 Replies)
Discussion started by: Linux6.5
8 Replies

2. Shell Programming and Scripting

Comparision of two directories of diff servers

Hi All, I have transferred some directory structures from server1 to server2 by creating a tar files. Now i need to cross check whether I transferred entire structures or not. Is there any command to check this on each individual server. Thanks (2 Replies)
Discussion started by: nag_sathi
2 Replies

3. UNIX for Dummies Questions & Answers

Change chmod on files in diff directories

I am looking for a small script to crawl through several directories and change a couple of files in each directory to read write status. Anyone have any ideas ? (5 Replies)
Discussion started by: zapper222
5 Replies

4. UNIX for Dummies Questions & Answers

Help regarding effective usage of diff for comparing files

Help regarding effective usage of diff for comparing files Hi All, I have few doubts regarding best usage of diff command. I also have some questions with out put of diff command. File1: ABC DEF File2: ABC DEFAA diff file1 file2 2c2 <DEF ----- (1 Reply)
Discussion started by: sarbjit
1 Replies

5. Homework & Coursework Questions

comparing 2 directories

i have been asked to write a bash shell script comparing two directories and sed or awk should not be used in this assignment. compdir will compare filenames in two directories, and list information about filenames that are in one directory but not the other. The information listed will be a long... (1 Reply)
Discussion started by: soccerball
1 Replies

6. UNIX and Linux Applications

CVS recursive diff -- how to exclude specific directories?

I think I've seen out there that there is a command to ignore specific files within a directory when doing a (-R) recursive diff. I've never used this so I was wondering if there was anyone who could provide an example how I would run this. My thoughts are something like: cvs diff -i <fileName1>... (2 Replies)
Discussion started by: airon23bball
2 Replies

7. UNIX for Dummies Questions & Answers

Using diff on files in different directories

Hi, I want to be able to compare two different files in two different directories. I have a development server set up on one domain and a live server set up on another.....I need to be able to compare files on these two servers. Any ideas? (2 Replies)
Discussion started by: elduderino
2 Replies

8. UNIX for Dummies Questions & Answers

Compare/Diff between directories and subdirectories?

Hi, Does anybody know the cmd to compare two areas and print out the different files w/ path? I tried cmp and diff and dircmp but with no luck. Should I grep and print? For example: /aa/images/jan ..../images/feb /bb/images/jan ..../images/feb i want to print the compare,... (5 Replies)
Discussion started by: andylee80
5 Replies

9. UNIX for Dummies Questions & Answers

perform diff between 2 directories

Hello all i wander what is the best way to make diff between 2 directories and perform diff of 2 kinds the first is the names of the files on each directory , and the second diff is between the content of each file and the corresponding file and the second dir. Thanks for the help (5 Replies)
Discussion started by: umen
5 Replies

10. Shell Programming and Scripting

perl package directories - what if the script is diff DIR to the one contain *.pm?

Hi there, say the package is in the ~/ and it's ~/packageFoo.pm I can use usePackage.pl in ~/ (~/usePackage.pl). Now, if I move it to ~/subDIR/usePackage.pl, the script won't work because it's not in the same DIR with packageFoo.pm How can i fix it? Thanks Gusla (1 Reply)
Discussion started by: gusla
1 Replies
Login or Register to Ask a Question