Chmod Command Cheatsheet: Understanding and Using File Permissions in Linux

Chmod Command Cheatsheet: Understanding and Using File Permissions in Linux

Understanding and Using File Permissions in Linux

ยท

3 min read

Introduction:

One of the most important concepts in Linux is file permissions. It's what allows you to control who can read, write, and execute files and directories on your system. The chmod (change mode) command is used to change the permissions of files and directories in Linux. It's a powerful command, and mastering it can be a bit tricky, especially for new Linux users. In this post, we'll go over a chmod command cheatsheet with examples to help you understand and use file permissions in Linux.

What is chmod?

The chmod command is used to change the permissions of files and directories in Linux. It allows you to specify which users and groups can read, write, and execute a file or directory. The chmod command works by changing the mode of a file or directory. The mode is a set of three octal (numeric) digits that specify the permissions for the file's owner, group, and others.

Permission Types:

  • r: read

  • w: write

  • x: execute

Permission Classes:

  • u: user (owner)

  • g: group

  • o: other

  • a: all (user, group, and other)

Syntax:

The basic syntax for chmod is:

chmod [permission] [file or directory]

Numeric Notation:

  • The first digit represents the owner's permissions

  • The second digit represents the group's permissions

  • The third digit represents the permissions for others

  • Each digit can have a value between 0 and 7

Examples:

chmod 755 file.txt  # grants owner read, write and execute permissions and read, execute permissions for group and other
chmod 744 file.txt  # grants owner read, write permissions and read permissions for group and other
chmod 700 file.txt  # grants owner read, write and execute permissions, no permissions for group and other

Symbolic Notation:

  • "+" adds a permission

  • "-" removes a permission

  • "=" sets the exact permissions

Examples:

chmod u+rwx file.txt # grants owner read, write, and execute permissions
chmod g+rw file.txt # grants group read and write permissions
chmod o-r file.txt  # removes read permissions for others
chmod a=rw file.txt # sets read and write permissions for owner, group and others

Conclusion:

In this post, we've covered the basics of the chmod command, including its syntax, numeric notation, and symbolic notation. We've also provided examples of how to use the command to change file permissions in Linux. Remember that changing the permissions of important system files can cause issues with your system, so it's always recommended to back up any important files before modifying their permissions. With this cheat sheet, you should have a better understanding of how to use the chmod command to manage file permissions in Linux.

Did you find this article valuable?

Support vishnu chilamakuru by becoming a sponsor. Any amount is appreciated!

ย