Access Permissions

For File

  • r - O_RDONLY or O_RDWR
  • w - O_WRONLY, O_RDWR, or O_TRUNC
  • x - execute a file

For Directory

Read Permission

This allows you to list what is inside the directory (we should think of directory as a file, so read permission means allow you to read the directory file content)

However, you can’t access any of the file or use directory as part of the path (this is for execute permission)

For example, we need read permission to ls

Write Permission

This allows you to create or delete a file inside the directory. Creating or deleting a file in UNIX means to add or remove entry from the directory file, thus we need to have permission to have the kernel modify the directory file’s content

However, creating or removing a file also require execute permission. This is because we must use special system calls to have kernel modify the directory file, and these system calls request for file path as argument, which we need execute permission to understand

Deleting a file in the directory doesn't require permission on the file, we only need the write and execution permission of its parent directory since deleting a file is just removing an entry on directory file

Execute Permission

Execute permission gives us permission to access the files inside the directory, i.e., it allows us to include this directory as part of the file path

For example: with --x permission, we can cd into the directory, but we can’t actually see what is inside the directory because we don’t have read permission