Chmod With Numbers
Part of the Fundamentals section of Coddy's Terminal journey — lesson 55 of 82.
The chmod command lets you change file permissions. One way to use it is with numeric mode, where each permission is represented by a number.
Each permission has a value: read is 4, write is 2, and execute is 1. You add these values together to create a single digit for each user category. For example, read + write + execute = 4 + 2 + 1 = 7.
| Number | Permission | Meaning |
|---|---|---|
| 7 | rwx | read + write + execute |
| 6 | rw- | read + write |
| 5 | r-x | read + execute |
| 4 | r-- | read only |
| 0 | --- | no permissions |
You combine three digits to set permissions for owner, group, and others. For example:
chmod 755 script.shThis sets rwx (7) for the owner, r-x (5) for the group, and r-x (5) for others. A common permission like 644 gives the owner read and write access, while everyone else can only read the file.
Challenge
EasyYou have a script file deploy.sh that needs to be executable by the owner, but only readable by the group and others.
Use chmod with numeric mode to set the permissions on deploy.sh to:
- Owner: read, write, and execute (
7) - Group: read only (
4) - Others: read only (
4)
After setting the permissions, use ls -l deploy.sh to verify the change.
Your output should show the permission string -rwxr--r-- for the file.
Hint: The three digits you need are
744. Runchmod 744 deploy.shfollowed byls -l deploy.shto display the updated permissions.
Cheat sheet
The chmod command changes file permissions using numeric mode, where each permission has a numeric value:
- read =
4 - write =
2 - execute =
1
Add these values together to create permissions for owner, group, and others:
| Number | Permission | Meaning |
|---|---|---|
| 7 | rwx | read + write + execute |
| 6 | rw- | read + write |
| 5 | r-x | read + execute |
| 4 | r-- | read only |
| 0 | --- | no permissions |
Use three digits to set permissions for owner, group, and others:
chmod 755 script.shThis sets rwx for owner, r-x for group, and r-x for others.
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