2

How do I sort contents of two different folders before comparing those two directories using diff?

3
  • possible duplicate of compare two directory trees
    – Paul
    Commented Nov 5, 2014 at 4:41
  • can't use rsync. says not found
    – postit98
    Commented Nov 5, 2014 at 5:22
  • can I use comm in this?
    – postit98
    Commented Nov 5, 2014 at 5:40

1 Answer 1

1

You could use diff with process substitution:

diff <(ls -a dir1/) <(ls -a dir2/)
  • <(...) creates a file descriptor whose path is added as argument to diff.
  • When no sort option is given, ls sort the output alphabetically.
  • The two ls-outputs are give to diff for comparsion.

My example folders look like this:

.
├── dir1
│   ├── file1
│   ├── file2
│   └── file3
└── dir2
    ├── file2
    ├── file3
    └── file4

The output is this case is:

$ diff <(ls -a dir1/) <(ls -a dir2/)
3d2
< file1
5a5
> file4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .