Method: LinuxStat::User.usernames_by_uid
- Defined in:
- lib/linux_stat/user.rb
.usernames_by_uid(uid = get_uid) ⇒ Object
def usernames_by_uid(gid = get_uid)
Where uid is the group id of the user. By default it’s the uid of the current user.
It returns an Array containing the username corresponding to the uid.
For example:
LinuxStat::User.usernames_by_uid(1001)
=> ["userx", "usery"]
But if the info isn’t available it will return an empty Array.
172 173 174 175 176 177 178 179 180 |
# File 'lib/linux_stat/user.rb', line 172 def usernames_by_uid(uid = get_uid) return [] unless passwd_readable? usernames = [] passwd_splitted.each { |x| usernames << x[0] if x[2].to_i == uid } usernames end |