Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get username of file owner?

2,665 views
Skip to first unread message

John Fry

unread,
Jun 10, 2005, 5:46:02 PM6/10/05
to
Hi,

I'd like to get the username of the owner of a file in my Ruby
program. Getting the uid is easy:

File.stat("testfile").uid -> 501

Anyone have a suggestion on how to get the actual username, like
"smith"?

I'm on Solaris without root and /etc/passwd does not list explicit
usernames.

Best,

John

Fredrik Fornwall

unread,
Jun 10, 2005, 6:57:16 PM6/10/05
to
Once you have the uid of a user you can get the user name by using
the getpwuid function in the Etc module
(http://rubygarden.org/ruby/ruby?ProgrammingRubyTwo/Etc).

Example:

require 'etc'
uid = File.stat('testfile').uid
puts 'Owner name: ', Etc.getpwuid(uid).name

0 new messages