File Permissions¶
As we learned previously, files have different permissions or file modes. Let's look at an example:
There are four parts to a file's permissions. The first part is the filetype, which is denoted by the first character in the permissions. In our case, since we are looking at a directory, it shows d
for the filetype. Most commonly, you will see a -
for a regular file.
The next three parts of the file mode are the actual permissions. The permissions are grouped into 3 bits each. These bits represent: - User permissions - Group permissions - Other (everyone else) permissions
I've added the pipe to make it easier to differentiate:
Each character represents a different permission: - r: readable - w: writable - x: executable (used for executable files and directories) - -: empty (no permission)
Example Breakdown:¶
In the example drwxr-xr-x
, we can break it down as:
- File type: d
(it's a directory)
- User (owner): rwx
(the user "mo" has read, write, and execute permissions)
- Group: r-x
(the group "staff" has read and execute permissions)
- Others: r-x
(all other users have read and execute permissions)
Exercise¶
Use the ls -l
command on multiple files in your directory and analyze their:
- File type
- Permissions (user, group, and others)
- User (owner) and Group
Try experimenting with different files and directories to get familiar with permission structures.
Quiz Questions¶
Click the arrow to check your answers.
What permission bit is used for executable files or directories?
**x** (executable)What does the first character of file permissions represent?
It represents the **file type**. For example, `d` for directory, `-` for regular files, and other special characters for things like links.What does the `w` permission allow?
**w** stands for **writable**, meaning the file or directory can be modified.In the permissions `rwxr-xr-x`, what permissions does the group have?
The group has **read** and **execute** permissions (`r-x`).Interactive Multiple Choice Quiz¶
1. Which of the following describes a file with read and write permissions for the user and read-only permissions for everyone else?
2. What does the x
permission allow on directories?
3. Which command would you use to change the permissions of a file?
Summary¶
- File permissions are essential for managing access control in Linux.
- Always check and modify file permissions carefully to avoid security risks or unwanted file access.
- Use the
ls -l
command to view file permissions andchmod
to modify them.