Reading Permissions
Part of the Fundamentals section of Coddy's Terminal journey — lesson 54 of 82.
Now that you understand what permissions are, let's learn how to read the permission string that ls -l displays.
The permission string has 10 characters. The first character indicates the type: - for a regular file, d for a directory. The remaining 9 characters are divided into three groups of three:
-rwxr-xr--
│└┬┘└┬┘└┬┘
│ │ │ └── Others: r-- (read only)
│ │ └───── Group: r-x (read and execute)
│ └──────── Owner: rwx (read, write, execute)
└────────── Type: - (regular file)Each position in a group represents a specific permission. If the letter is present, the permission is granted. If there's a dash -, the permission is denied.
| Position | Letter | Meaning |
|---|---|---|
| 1st | r | Read |
| 2nd | w | Write |
| 3rd | x | Execute |
So r-x means read and execute are allowed, but write is not. And rw- means read and write are allowed, but execute is not.
Challenge
EasyUse ls -l to display the detailed file listing and examine the permission strings for each item.
Look at the output and identify the permissions for each file and directory. For each item, read the 10-character permission string and determine:
- Whether it's a file (
-) or directory (d) - What permissions the owner has (first group of three)
- What permissions the group has (second group of three)
- What permissions others have (third group of three)
Run the command:
ls -lIn the output, notice how backup.sh has execute permission (x) for the owner, making it runnable as a script. Compare this to report.txt and config.cfg which are regular files without execute permission.
Also observe how the projects directory starts with d instead of -, and has execute permission which allows users to enter the directory.
Cheat sheet
The permission string displayed by ls -l has 10 characters:
-rwxr-xr--
│└┬┘└┬┘└┬┘
│ │ │ └── Others: r-- (read only)
│ │ └───── Group: r-x (read and execute)
│ └──────── Owner: rwx (read, write, execute)
└────────── Type: - (regular file)The first character indicates the type:
-for a regular filedfor a directory
The remaining 9 characters are divided into three groups of three, representing permissions for owner, group, and others.
Each position represents a specific permission:
| Position | Letter | Meaning |
|---|---|---|
| 1st | r | Read |
| 2nd | w | Write |
| 3rd | x | Execute |
If the letter is present, the permission is granted. If there's a dash -, the permission is denied.
Examples:
r-xmeans read and execute are allowed, but write is notrw-means read and write are allowed, but execute is not
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder11Permissions
Understanding PermissionsReading PermissionsChmod With NumbersChmod With SymbolsFile OwnershipRecap - Lock It Down6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline