Skip to main content

Unit 2 · Basic Commands · Lesson 19 of 34

Permission Paradise

ls -l and chmod

Now that you know how ownership works, it's time to see how Linux actually shows it to you, and how you can manage it.

The command you already know is ls, which lists files and folders in a directory. Add the -l flag (ls -l) and it lists out something much more useful: the permissions of every file in that directory.

Permissions come in three types:

  • read (r) → the ability to see a file's contents
  • write (w) → the ability to change a file
  • execute (x) → the ability to run a file

And remember those three questions from the last lesson (owner, group, everyone else)? This is exactly where they show up. Every file's permissions are actually split into those three scopes, so ls -l isn't showing you one set of read/write/execute, it's showing you three, one for the owner, one for the group, and one for everyone else.

Here's what one line of ls -l looks like:

-rwxr-xr-- 1 karl karl 220 Oct 19 12:00 script.sh

That first chunk, -rwxr-xr--, is the permissions. Break it up like this:

PartWhat it means
-What it is: - is a file, d is a directory
rwxThe owner (karl) can read, write, and execute
r-xThe group (karl) can read and execute, but not write
r--Everyone else can only read

A - in place of a letter just means that permission is missing. The two karls after it are the file's owner and group, in that order.

To add or remove these permissions, we use the chmod (change mode) command. chmod takes two arguments:

  1. Who you're changing permissions for, plus + or -, plus the permission itself:
    • u = owner, g = group, o = everyone else
    • r, w, or x for the permission
  2. The file being altered

For example:

  • chmod u+x script.sh → gives the owner permission to execute the file
  • chmod o-w finaldraft.txt → removes write access for everyone else, so only the owner (and maybe the group) can edit it

If you leave out the u/g/o, like chmod +x script.sh, Linux just applies the change to everyone. Handy for quick fixes, but now you know exactly what's happening under the hood.

Live Linux terminal

This lesson comes with a real Ubuntu machine that runs in your browser, so you type every command yourself. Create a free account to do this part.

Do this lesson for real

With a free account you get the terminal, the challenges and the checks that go with every lesson in Intro to Linux, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.