Back to course

Introduction to Permissions: chmod Basics

Termux Masterclass: From Zero to Linux Power User on Android

11. Introduction to Permissions: chmod Basics

File permissions are crucial in Linux for security and function (especially for scripts). Permissions define who can do what with a file or directory.

Viewing Permissions (The ls -l output)

When you use ls -l, the first 10 characters define the permissions:

-rwxr-xr--

  1. First Character (- or d): File type (- for file, d for directory).
  2. Next 3 Characters (rwx): Permissions for the User (Owner).
  3. Next 3 Characters (r-x): Permissions for the Group.
  4. Last 3 Characters (r--): Permissions for Others (Everyone else).
CharacterMeaning
rRead (view content)
wWrite (modify or delete)
xExecute (run as a program/script)
-Permission denied

Changing Permissions (chmod)

chmod (Change Mode) modifies permissions. We often use the Octal (numeric) notation:

PermissionOctal Value
Read (r)4
Write (w)2
Execute (x)1

Total permissions are the sum of values (e.g., rwx = 4+2+1 = 7).

Common Permission Sets:

  • 777 (rwxrwxrwx): Full permission for everyone (Rarely recommended).
  • 755 (rwxr-xr-x): Owner can read/write/execute; Group/Others can read/execute.
  • 644 (rw-r--r--): Owner can read/write; Group/Others can only read.

Example: Making a Script Executable

To run a script, it must have execute permission (x):

bash $ touch script.sh $ ls -l script.sh -rw-rw-rw- 1 u0_a... u0_a... 0 Jun 1 10:00 script.sh

Change permissions to 755 (User: rwx, Group/Other: r-x)

$ chmod 755 script.sh

$ ls -l script.sh -rwxr-xr-x 1 u0_a... u0_a... 0 Jun 1 10:00 script.sh