// Linux Basics

Linux permissions made understandable

Read, write and execute: what those cryptic letters really mean.

Linux files have an owner, a group, and permissions for everyone else. These permissions are worth learning before you install scripts from the internet.

Read an ls -l listing

ls -l ~/darkpc-hello.txt

Example output begins with -rw-r--r--. The first character describes the item (- file or d directory), and the next three groups represent owner, group and others.

Symbol Permission On a directory
r Read List filenames
w Write Create/delete entries (usually with x)
x Execute Enter/traverse

Make a script executable

mkdir -p ~/darkpc-lab
printf '#!/bin/sh\necho Hello from DarkPC\n' > ~/darkpc-lab/hello.sh
chmod u+x ~/darkpc-lab/hello.sh
~/darkpc-lab/hello.sh

chmod u+x gives the user/owner execute permission. You can run a script without making it executable using sh path/to/script.sh, if it is a compatible shell script.

The numeric form

chmod 755 file means owner can read/write/execute, while group and others can read/execute. chmod 600 file makes a regular file readable and writable only by its owner.

Who owns a file?

id
stat ~/darkpc-lab/hello.sh

Avoid using chmod 777 as a quick fix: it gives everyone write permission and is rarely appropriate.