From: Daniel Berger Date: 2009-06-10T00:48:04+09:00 Subject: Re: Find out the name of a user, on a given file/dir/symlink? > -----Original Message----- > From: shevegen@linuxmail.org [mailto:shevegen@linuxmail.org] > Sent: Tuesday, June 09, 2009 8:43 AM > To: ruby-talk ML > Subject: Find out the name of a user, on a given file/dir/symlink? > > Right now I use this: > > require 'fileutils' > require 'etc' > require 'pp' > > FileUtils.touch 'test' > > name = Etc.getpwuid(File.stat('test').uid).name > > puts name > > > This gives me the name of the file/dir/symlink in question, i.e > who owns it. > > However, I found this is a bit long. Anyone knows of a shorter > way? Specifically I wonder if I have to use both Etc. and File. > or if I can just one one of these two. > > I didn't find a quick way to just retrieve the name in class File > though. That's about as good as it gets. You can always re-open the File class if this is something you need on a regular basis: class File def self.owner(file) Etc.getpwuid(stat(file).uid).name end end Regards, Dan