How to diff file names in two directories (without writing to intermediate files)?

I am trying to do something along the lines of:

diff `ls -1a ./dir1` `ls -1a ./dir2` 

But that doesn't work for obvious reasons. Is there a better way of achieving this (in 1 line), than this?

ls -1a ./dir1 > lsdir1 ls -1a ./dir2 > lsdir2 diff lsdir1 lsdir2 

Thanks

2 Answers

You were close. In bash you want process substitution, not command substitution:

diff <(ls -1a ./dir1) <(ls -1a ./dir2) 
2
diff -rq dir1 dir2 

using the -r option, walk entire directory trees, recursively checking differences between subdirectories and files that occur at comparable points in each tree. The trick is to use the -q option to suppress line-by-line comparisons

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like