Method: LinuxStat::User.uid_by_username
- Defined in:
- lib/linux_stat/user.rb
.uid_by_username(username = get_user) ⇒ Object
uid_by_username(username = get_user)
Where username is the username to look for, by default it is the current user.
It returns the uid by the username.
For example:
LinuxStat::User.uid_by_username('root')
=> 0
The return type is Integer.
But if user passed doesn’t exist or if the info isn’t available, it will return nil.
247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/linux_stat/user.rb', line 247 def uid_by_username(username = get_user) return nil unless passwd_readable? uid = nil passwd.each do |x| splitted = x.split(?:.freeze) if splitted[0] == username uid = splitted[2].to_i break end end uid end |