Checking whether the file exists under a directory and doing a diff

Hi Everyone,

I am writing a shell script for the below needs and would like your suggestions and advices.

I have a lot of scripting files(Shell Scripts) under the directory:
/home/risk_dev/dev

I have another directory which has a lot of shell scripts under the directory:
/home/risk_dev/uat

Now, I am looking for the below things:

1) What are all the files that exists under the directory dev but not uat.
2) what are all the files (file names) that exists under the directory uat but not dev.
3) what are the files that are not matching.

For Example:
I thought To get the file list that are not matching is to do a diff -b and then get the file name if its not matching.

Could someone please share their thoughts which could be more simpler to find whether the file exists and the diff.

I would really appreciate your time and your thoughts.

In each dir do an "ls -1" to give you a single column of files. Output each to a new file. Then use comm to find the common and distinct files in each.

dev$ ls -1 >/tmp/dev.ls
dev$ cd ../uat
uat$ ls -1 >/tmp/uat.ls ;
cd /tmp
tmp$ comm dev.ls uat.ls

The man page on comm will tell you how to interpret the output and how to run it to get the results you want.

diff -q /home/risk_dev/dev /home/risk_dev/uat

If you need to compare the contents of subdirectories as well, you can recurse with -r.

Regards,
Alister