Skip to content

Reading permission strings

Module
Users and Basic Permissions
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21
Prerequisites
On this page

A long listing starts with -rwxr-x---, but the account names appear farther along the line. You need to connect those pieces before deciding who may read or change the file.

By the end, you can divide a real permission string into its type and three permission fields, identify which field applies, and explain the ordinary file operations each field permits.

Finish Identity and groups. Keep your B04 lab directory. Use only disposable ~/lab/b11/strings:

Terminal window
mkdir -p ~/lab/b11/strings/folder
cd ~/lab/b11/strings
printf 'Review copy\n' > report.txt
chmod 750 report.txt

The last command prepares the specific mode used for this reading exercise. chmod changes permission bits; its symbolic and numeric forms belong to B11.4, listed in the module outline. Here, use the setup exactly and inspect the result. The text file is deliberately given an execute bit for decoding; that bit does not turn its text into a useful program.

Use Reset this lesson before repeating the setup in an existing exercise directory.

Split the first field before reading the rest

Section titled “Split the first field before reading the rest”
Terminal window
ls -l report.txt
Captured output
-rwxr-x--- 1 learner learner 12 Nov 14 15:31 report.txt

This is an actual lab listing. The date, size, ownership names, and numeric identities may differ on your machine. The prepared first field should agree.

Start at the left. The first character is the file type. Here - means a regular file. The following nine positions describe three sets of permissions, always in this order: owning user, owning group, other users.

Part of the captured string Meaning
- Regular file
rwx Owner permission bits
r-x Group permission bits
--- Other permission bits

Within each three-character field, the positions are read, write, execute. A letter means that bit is set; - means it is absent. The order does not change when a bit is absent. In r-x, the middle dash occupies the write position.

Read the permission string in four parts The string starts with a regular-file marker. Owner has rwx, group has r-x, and other has no permission bits. -rwxr-x--- Type: - means regular file Owner: rwx Group: r-x Other: ---
Read the permission string in four parts The string starts with a regular-file marker. Owner has rwx, group has r-x, and other has no permission bits. -rwxr-x--- Type: - means regular file Owner: rwx Group: r-x Other: ---
The captured -rwxr-x--- field contains one type marker followed by owner rwx, group r-x, and other --- permissions.

In words: one character tells you what kind of entry this is, then three characters describe each access class. Do not count the type marker as part of the owner’s permissions.

For this regular file, read permission allows reading its bytes. Write permission allows modifying its contents. Execute permission allows attempting to run it as a program through its pathname. Execution still needs a valid executable format or suitable interpreter handling; permission bits alone do not establish that the contents are runnable.

The static decoder below applies those meanings to the captured string:

Access class Ordinary file permissions granted
Owner rwx: read contents, write contents, attempt execution
Group r-x: read contents and attempt execution; no content writing
Other ---: none of those three permissions

These statements describe the basic mode bits. Reaching the pathname also requires access through parent directories. Administrative privileges, access control lists, and filesystem restrictions can affect actual results. This lesson uses ordinary unprivileged access to a regular practice file, without additional ACL entries.

Write permission on a file does not by itself decide whether its name can be removed or renamed. Those operations modify directory entries. B11.3 examines that distinction directly.

Choose the field for the requesting identity

Section titled “Choose the field for the requesting identity”

Look back at the full listing. After the permission field and link count come the owning user and owning group. Both are learner here. The remaining fields show size, modification time, and name. A group name appearing in this line identifies the file’s owning group, not every group belonging to its owner.

For the basic permission check, choose one class:

  1. If the requesting user owns the file, use the owner bits.
  2. Otherwise, if the file’s group matches the requesting process’s primary or supplementary groups, use the group bits.
  3. Otherwise, use the other bits.

Permissions are not added across these classes. An owner whose owner field lacks a permission does not fall back to more generous group or other bits. Nor does a member of several groups collect permissions from several fields on this one file.

Predict first: does asking for numeric ownership change the permission bits?

Terminal window
ls -ln report.txt
Run it, then compare with your guess
Captured output
-rwxr-x--- 1 1001 1001 12 Nov 14 15:31 report.txt

No. -n asks for numeric user and group IDs in the listing. The same file still starts with -rwxr-x---. Formatting the identities does not change access.

Use -d to inspect the directory itself rather than list its contents:

Terminal window
ls -ld folder
Captured output
drwxr-xr-x 2 learner learner 4096 Nov 14 15:31 folder

The leading d identifies a directory. Its nine permission positions still belong to owner, group, and other, but their operations differ from a regular file’s. In particular, directory x means search or traversal permission. Decode the entry type before explaining what the bits allow.

Read the type, owner, group, and other fields
learner@rootvolt:~/lab$ cd ~/lab/b11/stringslearner@rootvolt:~/lab/b11/strings$ ls -l report.txt-rw-r--r-- 1 learner learner 12 Nov 14 15:32 report.txtlearner@rootvolt:~/lab/b11/strings$ chmod 750 report.txtlearner@rootvolt:~/lab/b11/strings$ ls -l report.txt-rwxr-x--- 1 learner learner 12 Nov 14 15:32 report.txtlearner@rootvolt:~/lab/b11/strings$ ls -ld folderdrwxr-xr-x 2 learner learner 4096 Nov 14 15:32 folderlearner@rootvolt:~/lab/b11/strings$ 

Files ~/lab/b11/strings

  • ~
    • lab/b11/strings/cwd
      • folder/listed
      • report.txt-rwxr-x---

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. A controlled chmod changes report.txt to the decoded mode; the Files panel records the changed bits and the terminal verifies them.
Steps (13)
  1. Type cd ~/lab/b11/strings
  2. Press Enter
  3. Type ls -l report.txt
  4. Press Enter
  5. Output: -rw-r--r-- 1 learner learner 12 Nov 14 15:32 report.txt
  6. Type chmod 750 report.txt
  7. Press Enter
  8. Type ls -l report.txt
  9. Press Enter
  10. Output: -rwxr-x--- 1 learner learner 12 Nov 14 15:32 report.txt
  11. Type ls -ld folder
  12. Press Enter
  13. Output: drwxr-xr-x 2 learner learner 4096 Nov 14 15:32 folder

The replay’s fixture starts with the same text file before the setup’s mode change. Its before/after listings are captured, not calculated by the browser. The table above supplies the complete static interpretation without an interactive decoder.

Reading the owning group as an access guarantee. Membership tells you which field to check; the field can still deny the requested operation.

Reading a missing-path error as a permission string.

Terminal window
ls -l missing.txt
Captured output
ls: cannot access 'missing.txt': No such file or directory

There is no metadata line to decode. Check the name and current directory first. A missing file and an existing file with --- permissions are different cases.

Goal: Inspect the current directory itself. Identify its type and all three permission fields. Explain whether learner should use the owner field here.

Hint

Use B05’s dot for the current directory and the option that prevents listing its contents.

Solution
Terminal window
ls -ld .
Captured output
drwxr-xr-x 3 learner learner 4096 Nov 14 15:31 .

The entry is a directory. In this capture, owner rwx, group r-x, and other r-x follow the type marker. User learner owns the directory and therefore uses its owner bits. Explain directory operations with the next lesson rather than assigning regular-file meanings to them.

Terminal window
cd ~/lab/b11
ls -AR strings
Terminal window
rm -r ~/lab/b11/strings

Rerun Before you start. Skip removal if the directory is absent. Removal and recreation were verified in the capture.

  • Read one type character, then owner, group, and other fields of three characters each.
  • Each field uses read, write, execute order; a dash marks an absent bit.
  • Ownership and membership select one class; their permissions are not combined.
  • Decode the entry type before translating its bits into operations.

Next, File versus directory permissions tests why listing a name and reaching its file are separate operations.