So, I've run the ls -C1
on two directories:
mod@ux:~$ ls -C1 /bin | wc -l
165
mod@ux:~$ ls -C1 /sbin | wc -l
167
How to list only different filenames/commands and which directory contains them?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityYou can have it compare directly against the directory structure:
$ diff /sbin /bin|sort
Only in /bin: arping
Only in /bin: attr
Only in /bin: awk
Only in /bin: basename
[...]
Only in /sbin: agetty
Only in /sbin: arp
Only in /sbin: arptables-compat
Only in /sbin: badblocks
You can add recursion too by specifying -r
, if you like. If you don't want to know about common subdirectories, add grep -v "Common subdirectories"
to the pipeline.
Execute diff <(ls -C1 /bin |sort) <(ls -C1 /sbin |sort) |less
.
With /bin
and /sbin
as input to the command above, diff
will append <
to files unique to /bin
and >
to files unique to /sbin
. If you need the <
and >
to be more informative, you can use sed
to replace them with more informative strings:
diff <(ls -C1 /bin |sort) <(ls -C1 /sbin |sort) |sed -e 's/^< /\/bin\//' -e 's/^> /\/sbin\//'
sort
at the end: diff <(ls -C1 /bin |sort) <(ls -C1 /sbin |sort) |sed -e 's/^< /\/bin\//' -e 's/^> /\/sbin\//' | sort