1

To compare the structure by iterating through each and every folder, I have tried to list the output(to a text file) of every directory and file present :

diff --brief -Nr dir1/ dir2/ > out.txt

The output I have got is only for difference in files. I want the output which will iterate through the folders and specify if the folder exists in another directory.This should be valid for complete structure, files as well as folders.

cat out.txt :

Files abc/def/xy.txt and pqr/def/xy.txt differ

Files abc/ooo/q.txt and pqr/ooo/q.txt differ

Files abc/ooo/t.txt and pqr/ooo/t.txt differ

1

Suppose two diretory trees: dir_one and dir_two. Then, assuming bash:

To list all that is in both dir_one and dir_two:

comm -12 <(cd dir_one ; find | sort) <(cd dir_two ; find | sort)

To list all that is present in dir_one, but not in dir_two:

comm -23 <(cd dir_one ; find | sort) <(cd dir_two ; find | sort)

And lastly, to list all that is not in dir_one, but is present in dir_two:

comm -13 <(cd dir_one ; find | sort) <(cd dir_two ; find | sort)
0

I want the output which will iterate through the folders and specify if the folder exists in another directory

Consider these directories/files:

tree dir1/ dir2/
dir1/
|-- bar
|-- foo
`-- subdir_dir1
dir2/
`-- foo

Wouldn't this diff variant meet your needs?

diff -rq dir1 dir2
Only in dir1: bar
Only in dir1: subdir_dir1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.