Linux `chmod` Command

Like many Linux commands, the typical syntax for chmod follows the pattern: first the command, then the options, and finally the file or directory to which it should be applied:

chmod [options] permissions /path/to/file

Before diving in, let’s review the types of Linux permissions and how they are set.
(If you’re not familiar with permissions, I recommend reading the linked article above first.)

Types of Permissions

There are three main permission types:

  • r – read
  • w – write
  • x – execute
  • s – execute with superuser privileges (special)

User Categories

You can set these permissions for three categories of users:

  • u – file owner (user)
  • g – group
  • o – others (everyone else)

Actions

To modify permissions, you can use the symbols:

  • + – grant permission
  • - – revoke permission

Examples:

  • u+x – allow execution for the owner
  • ugo+x – allow execution for everyone
  • ug+w – allow write permission for the owner and group
  • o-x – deny execution for others
  • ugo+rwx – allow all permissions for everyone

Numeric Permissions

Permissions for a directory in Linux work the same way as for files.
When setting numeric permissions, specify the owner’s value first, then the group’s, and finally others’. For example:

  • 744 – full access for the owner, read-only for others
  • 755 – full access for the owner, read & execute for others
  • 764 – full for the owner, read & write for group, read-only for others
  • 777 – full access for everyone

Each digit is independent; you choose exactly what’s needed.


Useful chmod Options

  • -c – display information about all changes made
  • -f – suppress error messages
  • -v – show detailed output
  • --preserve-root – prevent recursive operations on the root /
  • --reference – copy permissions from the specified file
  • -R – apply changes recursively
  • --version – display the utility version

Examples of Using chmod

chmod u+x file
chmod 766 file
ls -l file
chmod u-x file

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email