1

The diff command gives a list of details along with the difference of files/folders like this

dirs=`diff -aq new_dir/ old_dir`

gives:

Only in new_dir/: five Common subdirectories: new_dir/four and old_dir/four Common subdirectories: new_dir/one and old_dir/one

But I want only the folder/file name without the details that is: five,four and etc. That is without the details

I tried something like this:

dirs=diff -aq new_dir/ old_dir | grep 'Only in new_dir/: *'

I don't think this is the right way to get ONLY the difference of folders. Is there any better way to solve this?

My desired output:

five
seven 
six

and Not

Only in new_dir/: five 
Only in new_dir/: seven 
Only in new_dir/: six
1
  • Do you mean you don't want to see items which are Common in both? Or I am misunderstanding your question? Can you show your desired output? Also, do quote your dirs variable so that newlines are pressured. Commented Jul 8, 2013 at 16:53

2 Answers 2

2

You can do something like:

dir=$(diff -aq new_dir/ old_dir | awk -F": " '/Only in new_dir/{print $2}')
Sign up to request clarification or add additional context in comments.

Comments

2

If you only want to know what (sub-)directories exist in dirA that don't exist in dirB, you can do this:

comm -23 <(cd dirA; find . -type d -print | sort) <(cd dirB; find . -type d -print | sort)

That doesn't consider the actual contents of directories though. You could adapt the above to find the reverse - sub directories in dirB but not dirA - by replacing -23 with -13; or get the common subdirectories with comm -12.

It would get more difficult if you cared about the files in each directory or the contents of those files, but it seems like that may not be the case here...

1 Comment

Thanks for your answer. But @JS웃's is more relevant to me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.