-8

I have a couple of questions about the find command.

  1. How to show how many files and directories(only the result numbers) within the /var directory (and below) are owned by someone other than you or root.

  2. same as above, but this time is to show how many users.

  3. Modify the command to show those other owners (in alphabetical order) with the output numbered. It should be something like this:

   1  avahi-autoipd
   2  colord
   3  daemon
   4  dirmngr
   5  libuuid
   6  lp
   7  man
   8  mdm
   9  ntp
  10  speech-dispatcher
  11  syslog

Each of these questions should use 3 separate but very similar command lines.

EDIT: I figured it out by myself sudo find /var/ -not -user root -not -user myusername | wc -l

sudo find /var/ -not -user root -not -user myusername -printf '%u\n' | sort -u | wc -l
sudo find /var/ -not -user root -not -user myusername -printf '%u\n' | sort -u

These command lines will do the same thing too: Part1:

sudo ls -oAu1QBR /var | tr -s ' ' | cut -d' ' -f3 | grep -Ev '(\"|root|^[[:space:]]*$)' | grep -v ${USER} | wc -l

Part2:

sudo ls -oAu1QBR /var | tr -s ' ' | cut -d' ' -f3 | grep -Ev '(\"|root|^[[:space:]]*$)' | grep -v ${USER} | sort -u | wc -l

Part3:

sudo ls -oAu1QBR /var | tr -s ' ' | cut -d' ' -f3 | grep -Ev '(\"|root|^[[:space:]]*$)' | grep -v ${USER} | sort -u | nl
1
  • 2
    We're not here to do your homework for you. Feel free to ask any questions that come up while solving it yourself.
    – Minix
    Jun 4, 2015 at 22:14

1 Answer 1

0

Have I already mentioned I like zsh's glob qualifiers?

files_in_var_not_owned_by_me_or_root=(/var/**/*(^u0u$UID))
echo $#files_in_var_not_owned_by_me_or_root

typeset -U owners_of_files_in_var
zstat -s -A owners_of_files_in_var +uid -- $files_in_var_not_owned_by_me_or_root
echo $#owners_of_files_in_var

i=1
for x in ${(o)owners_of_files_in_var}; do
  printf '%4d  %s\n' $((i++)) $x
done

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