unix - sort content of two folders then compare using diff command

2

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

postit98

Posted 2014-11-05T04:16:17.620

Reputation: 21

possible duplicate of compare two directory trees

– Paul – 2014-11-05T04:41:59.540

can't use rsync. says not found – postit98 – 2014-11-05T05:22:11.183

can I use comm in this? – postit98 – 2014-11-05T05:40:28.150

Answers

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

chaos

Posted 2014-11-05T04:16:17.620

Reputation: 3 704