Ubuntu – How to get a list of all owners of files in a directory

command linefilesystempermissionsquota

I am currently trying to fix my quota system. My problem is that I cannot determine if all files in a directory are owned by the same user. If possible is there a way to list the different owners of files in a directory (recursively).

e.g get-owners-of DIRNAME

Best Answer

You can use find to print the user (owner) and group and then extract the uniq combinations e.g.

$ sudo find /var -printf '%u:%g\n' | sort -t: -u
_apt:root
avahi-autoipd:avahi-autoipd
clamav:adm
clamav:clamav
colord:colord
daemon:daemon
lightdm:lightdm
lp:lp
man:root
root:adm
root:crontab
root:lp
root:mail
root:mlocate
root:root
root:shadow
root:staff
root:syslog
root:utmp
root:whoopsie
speech-dispatcher:root
statd:nogroup
steeldriver:crontab
steeldriver:lightdm
steeldriver:steeldriver
syslog:adm
systemd-timesync:systemd-timesync
testuser:crontab