Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Forked from moreati/example.md
Created May 19, 2018 06:13
Show Gist options
  • Save lbvf50mobile/19009ed383c654efcf80477cdec2f77b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/19009ed383c654efcf80477cdec2f77b to your computer and use it in GitHub Desktop.
Read and Execute permissions on Linux directories, by example

Preperation

Create 3 top-level directories. Create a file and a directory in each.

$ mkdir r rx x
$ touch {r,rx,x}/file
$ mkdir {r,rx,x}/dir

Apply read only, read + execute, and execute only permissions to the respective top-level directories

$ chmod ugo=r r
$ chmod ugo=rx rx
$ chmod ugo=x x

The top-level directories now have the following attributes

dr--r--r-- 3 alex alex 4096 Nov 17 18:48 r
dr-xr-xr-x 3 alex alex 4096 Nov 17 18:48 rx
d--x--x--x 3 alex alex 4096 Nov 17 18:48 x

Each directory contains the following

drwxrwxr-x 2 alex alex 4096 Nov 17 18:48 dir
-rw-rw-r-- 1 alex alex    0 Nov 17 18:48 file

Read only

We can ls the directory. However only the name of each item, and whether it is a directory or a file. We cannot stat any of the contained items, so no ownership, size or permissions are revealed.

$ ls -l r/
ls: cannot access 'r/dir': Permission denied
ls: cannot access 'r/file': Permission denied
total 0
d????????? ? ? ? ?            ? dir
-????????? ? ? ? ?            ? file

We cannot list or read any of the contained items

$ ls r/dir
ls: cannot access 'r/dir': Permission denied
$ cat r/file
cat: r/file: Permission denied

We cannot cd into the directory

$ cd r
bash: cd: r: Permission denied

Read + execute

We can ls the directory, and stat all contained items.

$ ls -l rx
total 4
drwxrwxr-x 2 alex alex 4096 Nov 17 18:48 dir
-rw-rw-r-- 1 alex alex    0 Nov 17 18:48 file

We can list or read all of the contained items

$ ls rx/dir
$ cat rx/file

We can cd into the directory

$ cd rx

Execute only

We cannot ls the directory

$ ls -l x
ls: cannot open directory 'x': Permission denied

We can list or read the contained items, but only if we already know (or can guess) their name

$ ls x/dir
$ cat x/file

We can cd into the directory

$ cd x

Notes

  1. The preceding examples we're obtained on Ubuntu Linux 16.04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment