What is the chmod command?

The chmod command in Unix-like systems is used to change the file permissions of a file or directory. It stands for "change mode." With chmod, you can specify who can read, write, or execute a file.

Basic Syntax

chmod [options] mode file

Common Options

  • + : Adds a permission
  • - : Removes a permission
  • = : Sets the permission and overrides existing ones

Modes

Permissions can be set using:

  • Symbolic notation:
    • u : user (owner)
    • g : group
    • o : others
    • r : read
    • w : write
    • x : execute

Example:

chmod u+x file.txt  # Adds execute permission for the user
  • Octal notation:
    • 4 : read
    • 2 : write
    • 1 : execute

Example:

chmod 755 file.txt  # Sets read, write, execute for user; read, execute for group and others

Example Command

To make a script executable:

chmod +x script.sh

This command adds execute permission to the script.sh file.

0 Comments

no data
Be the first to share your comment!