0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ディレクトリの検索権限と読取権限について

0
Posted at

環境

Ubuntu20.4

はじめに

権限設定のxについてですが、ファイルに付加した場合は実行権限といいますが、ディレクトリに付加した場合は実行権限とはいわず検索権限といいます。

確かに、ディレクトリの実行権限って一体何を実行するのだろうと疑問に思うことでしょう。

そのディレクトリの検索権限と混合しがちな読み取り権限の違いについて書いてみました。

検索権限のみ

testディレクトリのユーザーに検索権限だけを付けます。

$ ls -l
d--x------ 2 vagrant vagrant 4.0K 2025-02-17 09:42:43 test

testディレクトリ配下にあるファイルを参照することはできます。

$cat test/test.txt
test

しかし、testディレクトリをlsすることはできません。

$ls test
ls: cannot open directory 'test': Permission denied

cdでtestディレクトリに移動することはできます。

$cd test

しかし、testディレクトリ配下でlsをすることはできません。

$ls
ls: cannot open directory '.': Permission denied

testディレクトリに移動して、配下にあるファイルを参照することはできます。

$cat test
test

検索権限と読み取り権限

testディレクトリにユーザーに検索権限と読み取り権限を付けます。

ls -l
dr-x------ 2 vagrant vagrant 4.0K 2025-02-17 09:42:43 test

testディレクトリ配下をlsすることできます。

$ls test
test.txt

testディレクトリ配下にあるファイルを参照することもできます。

$ cat test/test.txt
test

cdでtestディレクトリに移動して、testディレクトリでlsをすることも、ファイルを参照することもできます。

$ls
test.txt

$ cat test.txt
test

読み取り権限のみ

testディレクトリにユーザーに読み取り権限だけを付けます。

$ls -l
dr-------- 2 vagrant vagrant 4.0K 2025-02-17 09:42:43 test

testディレクトリ配下をlsするとエラーになります。エラーの下に参照されてたりします。

ls test
ls: cannot access 'test/test.txt': Permission denied
test.txt

testディレクトリ配下にあるファイルを参照することはできません。

$ cat test/test.txt
cat: test/test.txt: Permission denied

testディレクトリに移動することもできません。

$ cd test/
-bash: cd: test/: Permission denied
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?