11.5 Viewing Permissions with ls -l: Decoding the Output
Right, let’s get our hands dirty with ls -l. This is where you stop just seeing files and start seeing files. It’s the decoder ring for the secret language of permissions, ownership, and all the other metadata the system uses to decide if you’re allowed to do what you’re trying to do.
Running it in a directory gives you that glorious, slightly intimidating, multi-column output. Let’s break down what each piece of this digital dossier actually means.
$ ls -l
total 24
-rw-r--r-- 1 alice developers 4096 Mar 15 10:23 my_recipe.txt
drwxr-xr-x 2 alice developers 4096 Mar 15 10:24 secret_sauce/
-rwxr-xr-- 1 bob developers 8192 Mar 15 10:25 bake_bread*
The Permission String: That First Weird Column
This 10-character string is the main event. Let’s dissect it left to right.
Character 1: File Type. The
-formy_recipe.txtmeans it’s a regular file. Thedforsecret_sauce/means it’s a directory. This is crucial. Linux treats directories as special types of files, and the execute permission on them means something completely different (more on that later). You might also seelfor a symbolic link—think of it as a fancy shortcut.Characters 2-4: User (Owner) Permissions. These three characters (
rw-in the first example) tell you what the user who owns the file can do. In this case, useralicecan Read and Write tomy_recipe.txt, but not execute it (the-is a placeholder for “permission not granted”). That makes sense; it’s a text file, not a program.Characters 5-7: Group Permissions. This (
r--in the first example) defines what members of the file’s group can do. Anyone in thedevelopersgroup can Read the file, but they can’t Write to it or execute it. This is a common setup for collaborative files: the owner can edit, the team can view.Characters 8-10: Other (World) Permissions. This (
r--) is the permission for everyone else on the system who isn’t the owner and isn’t in the group. It’s the “general public” setting. Here, they can also only read it.
The Numeric Ugly Bits: Links, User, and Group
The next few columns are simpler but just as important.
The Number (e.g.,
1): Hard Link Count. For a file, this is how many hard links point to it. For a directory, it’s a minimum of 2 (the directory itself and the.entry inside it) plus one for each subdirectory (each of which has a..entry pointing back). It’s a niche detail, but if you see a number wildly higher than expected, you’ll know why.User & Group: The Ownership Duo. Next you see the user who owns the file (
alice) and the group assigned to it (developers). This is the core of the permission model. The system checks “is the current useralice? If not, are they in thedevelopersgroup? If not, they must be ‘Other’.” It runs down that list until it finds a match and then applies the corresponding permissions.
Size, Date, and Name
The rest is fairly self-explanatory, but let’s be thorough.
- Size: The size in bytes. Remember, for a directory, this isn’t the size of its contents, just the metadata for the directory itself. Use
dufor the real space usage. - Timestamp: The last modification time by default. This is when the file’s content was last changed. Use
ls -lufor last access time orls -lcfor last status change (like a permission update). - Filename: The name of the thing. The trailing
/is a clue fromlsthat it’s a directory, and the*is a clue that it’s executable. These are just helpful hints, not part of the actual filename.
The Execute Permission: It’s Not What You Think
This is where people get tripped up. The execute bit (x) means two entirely different things:
On a file: It means the file can be executed as a program. A script without this bit set will throw a
Permission deniederror even if you can read it. You must explicitly give it the permission to run.$ ./bake_bread bash: ./bake_bread: Permission denied $ chmod +x bake_bread # Give it the execute permission $ ./bake_bread Baking delicious bread...On a directory: It’s not about executing anything. It’s the permission to access the directory. Specifically, it allows you to
cdinto it and access any file or subdirectory inside it whose own permissions allow it. A directory with read but not execute is like having a phonebook (you can see the list of names/files) but the door to the building is locked (you can’t access any of them). It’s a brilliantly weird design choice that makes perfect sense once you get it.
So, if you can’t cd into a directory you know exists, check for x in the ‘other’ permissions. That’s almost always the culprit.