8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyでファイルの所有ユーザ・グループを調べる

Last updated at Posted at 2015-06-01

ミドルウェアの設定ファイルなどを書くときにディレクトリの権限をいじる必要が時たまあると思う。1個ならlsたたけばすぐわかるけどいっきにいろいろなディレクトリを調べたいときにはコードで書く必要がありそうなので調べた。

Fileコマンドでは取れなかったのでEtcや、File::Statを利用したりする。

require 'etc'

path = '/'
user = Etc.getpwuid(File.stat(path).uid).name
group = Etc.getgrgid(File.stat(path).gid).name
puts "#{user}:#{group} #{path}" #=> root:root /
8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?