Differences between 2 directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Differences between 2 directories
# 1  
Old 11-22-2010
Differences between 2 directories

Hi,

I am trying to write a script under ksh to list all the differences between two directories.

For example:
Code:
 
[root@test-centos01 home]# ls
test1  test2

I need to compare all the files under between test1 & test2. When I do diff, it only compares the diectoires but it doesn't check inside. I did do with -r.

Code:
[root@test-centos01 home]# diff -r test1 test2
Only in test2: 123.txt
Only in test1: ABC.txt

Thanks.
# 2  
Old 11-22-2010
Diff compares all relatively-identical-name files, what do you want?
# 3  
Old 11-22-2010
I have two directories as above. test1 & test2. Each of the directoires have few files in them. I want to compare all the files inside the above two directories. From the above you can see that 123.txt is under test2 directory. And ABC.txt is under test1. But now how do I make them compare between 123.txt and ABC.txt. I don't want to type each of them.
# 4  
Old 11-22-2010
Since 123.txt is only in folder test2, not in folder test1. So how do you compare the difference with this file in two folders?

If you need compare the file content in two folders, maybe you can try:

Code:
find test1 -type f |while read file1
do
  file2=$(echo $file1|sed 's/test1/test2/')
  echo "* show the different on file: $file1 and $file2"
  diff file1 file2
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare directories and copy differences (files) in a another directory

Hey im working on script that can compare 2 directory and check difference, then copy difference files in third diretory. here is the story: in folder one we have 12 subfolder and in each of them near 500 images hosted. 01 02 03 04 05 06 07 08 09 10 11 12 in folder 2 we have same subfolder... (2 Replies)
Discussion started by: nimafire
2 Replies

2. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

3. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

4. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

5. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

6. Shell Programming and Scripting

Compare File Differences in different directories

Hello, I am new to scripting and have been trying to compare two different directories, but with all the same file names in each directory for file changes. I have been doing it in baby steps and have been doing pretty good, but I have hit a few snags. Test 1 and Test 2 work great, but my... (4 Replies)
Discussion started by: dmaday
4 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

9. UNIX for Dummies Questions & Answers

du -s -k differences between two identical directories

I tarred a directory from a linux server to a solaris server. When I do a du -s -k on the directory, I get almost 150k difference in the file sizes. If I do a ls | wc -l, it is the same. If I look at the size of the individual files, it is the same. I did an ls on the 2 directories and... (6 Replies)
Discussion started by: csgonan
6 Replies
Login or Register to Ask a Question