Back to Blog

Understanding File Permissions | rwx & chmod | Mac/Linux Terminal

Sandy LaneSandy Lane

Video: Understanding File Permissions | rwx & chmod | Mac/Linux Terminal by Taught by Celeste AI - AI Coding Coach

Watch full page →

Understanding File Permissions | rwx & chmod | Mac/Linux Terminal

File permissions in Mac and Linux terminals control who can read, write, or execute files and directories. This guide explains how to interpret the `rwx` notation, understand the user, group, and others permission categories, and convert permissions into numeric codes like 755 and 644 for easy management.

Code

# Example: ls -l output showing permissions
# -rwxr-xr-x  1 user group 1234 Apr 10 12:34 script.sh

# Breakdown of permissions:
# - : file type (dash = regular file, d = directory)
# rwx : user (owner) permissions (read, write, execute)
# r-x : group permissions (read, no write, execute)
# r-x : others permissions (read, no write, execute)

# Numeric permission calculation:
# r = 4, w = 2, x = 1

# User: rwx = 4 + 2 + 1 = 7
# Group: r-x = 4 + 0 + 1 = 5
# Others: r-x = 4 + 0 + 1 = 5

# Numeric permission code: 755

# Using chmod to set permissions:
chmod 755 script.sh

# Another example:
# -rw-r--r-- means:
# User: rw- = 4 + 2 + 0 = 6
# Group: r-- = 4 + 0 + 0 = 4
# Others: r-- = 4 + 0 + 0 = 4
# Numeric code: 644

chmod 644 document.txt

Key Points

  • File permissions are shown as a 10-character string: file type plus three sets of rwx for user, group, and others.
  • Each permission letter stands for read (r), write (w), and execute (x); a dash (-) means that permission is denied.
  • The three permission groups control access for the file owner (user), the group, and everyone else (others).
  • Numeric permissions use values read=4, write=2, execute=1, summed per group to form codes like 755 or 644.
  • The chmod command applies numeric codes to files to set their permissions efficiently in the terminal.