Boss lesson · Unit 01
Permission denied
Read ls -l, fix a script that will not run, and learn who may do what
What you practise
- Read
ls -loutput, users and groups,rwxfor files vs directories,chmodin octal and symbolic form,chown,sudo, the executable bit and./script
Try a question from this lesson
Pick one
You wrote run.sh and you own it. Reason it out from the listing: why will it not run?
$ ./run.sh
bash: ./run.sh: Permission denied
$ ls -l run.sh
-rw-r--r-- 1 ada staff 120 May 2 run.shHint
Look at the letters in the first column. Which of r, w and x never appears?
Correct answer
Nobody has execute permission on it
Why
The first column holds the permissions. It shows r and w but no x anywhere, so nobody may execute the file, not even its owner. New files start without the execute bit.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Reading the mode
The first column of ls -l is ten characters: one for the type, then three groups of three.
Each group is read, write, execute, with a dash where the permission is missing. The groups apply to the file's owner, its group, and everyone else, in that order.
-rwxr-x--- 1 ada staff run.sh
│└┬┘└┬┘└┬┘
│ │ │ └ others: nothing
│ │ └ group staff: read, execute
│ └ owner ada: read, write, execute
└ type: - file, d folderConcept
Folders read the bits differently
On a folder, the three letters control its list of names, not the files themselves.
r lets you list the names. w lets you create, rename and delete entries. x lets you enter the folder and reach what is inside.
So deleting a file is a change to its folder: it needs w on the folder, not on the file.
drwxr-xr-x ada staff reports/
│││
││└ x: may cd into it
│└ w: may add and delete entries
└ r: may list the names9 more exercises in the app
- 2× type the answer
- 1× fill the blanks
- 3× multiple choice
- 1× true or false
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.