12
13

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.

ちょっと便利なコマンド|nameiでアクセス権を表示

Last updated at Posted at 2014-10-24

あるファイルにアクセスするには、パスの途中のディレクトリ達にも、全てアクセス権(パーミッション)がなければならない。

いちいち ls -ld しても良いのだけれど、全部一括で表示できるコマンドがあるね。という小ネタ。

例えば /home/testuser1/public_html/ に対して、「全ディレクトリに o+x が付いていること」を調べてみる。

ls -ld を使う場合

lsコマンドの利用例
[testuser1@localhost ~]$ ls -ld / /home /home/testuser1 /home/testuser1/public_html
drwxr-xr-x. 17 root      root      4096 Oct 19 13:02 /
drwxr-xr-x.  4 root      root        36 Oct 24 20:28 /home
drwx-----x   3 testuser1 testuser1   97 Oct 24 20:34 /home/testuser1
drwxrwxr--   2 testuser1 testuser1   23 Oct 24 20:58 /home/testuser1/public_html

namei を使う場合

util-linuxに含まれる namei というコマンドを使うと、こんな感じ。

nameiコマンドの利用例
[testuser1@localhost ~]$ namei -m /home/testuser1/public_html/
f: /home/testuser1/public_html/
 drwxr-xr-x /
 drwxr-xr-x home
 drwx-----x testuser1
 drwxrwxr-x public_html

わざわざパスを分解しなくても、一目瞭然で確認できた。
少し楽になった。:relaxed:

おまけ

途中に symbolic link を含む場合、インデントされ、わかりやすい表示になる。また -xオプションでマウントポイントを"D"表示にできる。

nameiコマンドの利用例2(symlink入り)
[root@localhost ~]# namei -m -x /home/testuser1/public_html
f: /home/testuser1/public_html
 Drwxr-xr-x /
 drwxr-xr-x home
 drwx------ testuser1
 lrwxrwxrwx public_html -> public_html.new
   drwxr-x--- public_html.new

ういやつじゃ。

※ 上記表示は、CentOS7 で実行した場合のもの。

12
13
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
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?