Method: LinuxStat::User.homes_by_uid

Defined in:
lib/linux_stat/user.rb

.homes_by_uid(id = get_uid) ⇒ Object

home_by_uid(id = get_uid)

Gets all the users home directory with user id.

It returns an Array in this format:

LinuxStat::User.homes_by_uid(1001)

=> ["/home/userx", "/home/usery"]

Assuming both the users share same UID.

If the info isn’t available, it will return an empty Array.



296
297
298
299
300
301
302
303
304
305
# File 'lib/linux_stat/user.rb', line 296

def homes_by_uid(id = get_uid)
  return [] unless passwd_readable?

  home = []
  passwd.each do |x|
    splitted = x.split(?:.freeze)
    home << splitted[5] if splitted[2].to_i == id
  end
  home
end