Skip to main content

chmod

About Unix Commands

Unix commands are a set of commands that are used to interact with the Unix operating system. Unix is a powerful, multi-user, multi-tasking operating system that was developed in the 1960s by Bell Labs. Unix commands are entered at the command prompt in a terminal window, and they allow users to perform a wide variety of tasks, such as managing files and directories, running processes, managing user accounts, and configuring network settings

Note: Linux is Unix-Like operating system!

About chmod

In a Unix-like operating system, chmod is used to change the permissions of a file or directory. The chmod command uses a three-digit number to set these permissions. The three digits are in the format ugo, which stands for User, Group, and Others.

Each digit can range from 0 to 7 and is the sum of read (4), write (2), and execute (1) permissions for each category.

  • Read (r): 4 in decimal, 100 in binary
  • Write (w): 2 in decimal, 010 in binary
  • Execute (x): 1 in decimal, 001 in binary

The three-bit binary number allows for eight different combinations (2^3 = 8) ranging from 000 to 111 in binary, or 0 to 7 in decimal

Examples

chmod 750

  • User: 7 (Read, Write, Execute) - 4+2+1 = 7
  • Group: 5 (Read, Execute) - 4+0+1 = 5
  • Others: 0 (No permissions) - 0+0+0 = 0

The user who owns the file will have read, write, and execute permissions. Members of the file's group will have read and execute permissions. Others will have no permissions.

chmod 640

  • User: 6 (Read, Write) - 4+2+0 = 6
  • Group: 4 (Read) - 4+0+0 = 4
  • Others: 0 (No permissions) - 0+0+0 = 0

The user who owns the file will have read and write permissions. Members of the file's group will have read permissions. Others will have no permissions.