The chmod command in Linux: change file permissions

Introduction

In Unix-like systems, each file and directory has a set of permissions that determine who can read, modify, or execute that resource. The chmod (change mode) command is the standard tool for changing those permissions from the command line. Understanding its operation is essential for system administrators, developers, and any user working with Linux.

Basic Permission Concepts

Permissions are represented by three types of access: read (r), write (w), and execute (x). Each is assigned to three user categories: the owner (user), the group (group), and others (others). Therefore, we see a string like -rwxr-xr– where the first character indicates the file type and the following nine correspond to the permissions for user, group, and others in that order.

A compact way to express these permissions is using octal notation. Each permission has a value: r=4, w=2, x=1. Adding the values of each category yields a digit between 0 and 7. For example, rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, and –x = 0+0+1 = 1. Thus, -rwxr-xr– is written as 754.

Symbolic Mode vs Octal Mode

chmod accepts two ways to specify the new mode: symbolic and octal.

  • Octal mode: written directly as a three-digit number (or four if special bits are included). Example: chmod 755 file.txt.
  • Symbolic mode: combines who (u, g, o, a), the operator (+, -, =), and the permission (r, w, x). Example: chmod u+x,go-r file.txt.

The symbolic mode is more readable when you want to modify only a single bit, while octal is quick for assigning a full set of permissions.

Practical Examples

  • chmod 600 file.conf → only the owner can read and write (typical use for sensitive configuration files).
  • chmod 644 index.html → owner can read and write; group and others can only read (common on web pages).
  • chmod 755 script.sh → owner can read, write, and execute; group and others can read and execute (ideal for executable scripts).
  • chmod go+w

    This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .