Skip to content
Codescope

File permissions & chmod

Nine bits, three groups of three. 644 is not a magic number — it is binary.

intro9 min7 steps

Before you start

Every file on Linux has a set of **permissions** that decide who is allowed to read it, change it, or run it. There are three categories of "who": the file's owner, the owner's group, and everyone else.

For each category there are three switches — read (r), write (w), execute (x) — so nine switches total. ls -l shows them as rwxr-xr--, and chmod 755 sets them using octal (base-8) numbers because each group of three bits fits in one digit.

This lesson walks through the nine bits, decodes an octal permission string, and shows what changes when you chmod +x a script.

Permission bits

mode 644 · read 4, write 2, execute 1
owner
1
r
1
w
0
x
rw- · 6
group
1
r
0
w
0
x
r-- · 4
others
1
r
0
w
0
x
r-- · 4

rw- r-- r--: the owner can read and write, everyone else can only read.

Step 1 of 7. rw-r--r-- is nine bits in disguise. `ls -l` prints ten characters. The first is the file type — `-` for a regular file, `d` for a directory, `l` for a symlink. The remaining nine are three groups of three. Each group answers the same three questions — read? write? execute? — for a different class of user: the owner, the file's group, and everyone else.

01 / 07

Step 01 / 07

rw-r--r-- is nine bits in disguise

ls -l prints ten characters. The first is the file type — - for a regular file, d for a directory, l for a symlink. The remaining nine are three groups of three.

Each group answers the same three questions — read? write? execute? — for a different class of user: the owner, the file's group, and everyone else.

session.shShell
ls -l notes.txt# -rw-r--r--  1 ana  staff  1024 Aug 14 09:12 notes.txtchmod 644 notes.txt      # rw- r-- r--chmod 755 script.sh      # rwx r-x r-xchmod u+x script.sh      # symbolic: add execute for the ownerchmod go-w shared.txt    # remove write for group and othersumask                    # 022 — bits masked off from new files