Kunle is a jazz saxophonist by night, and a GNU/Linux Sysadmin by day. Please help him to become more familiar with the chmod command.

  1. What is the history of the chmod command? Who invented it, and for what purpose?
  2. Give 3 examples of simple chmod commands.
  3. Give 3 examples of intermediate chmod commands.
  4. Give 3 examples of advanced chmod commands.

History of the chmod Command

The chmod (change mode) command is a Unix command used to change the access permissions of file system objects (files and directories). It was invented by Dennis Ritchie and Ken Thompson, who created the Unix operating system in the late 1960s at Bell Labs. The primary purpose of chmod is to control the access rights to files and directories, enabling users to set who can read, write, or execute a particular file or directory.

Examples of chmod Commands

Simple chmod Commands:

  • Grant read and write permissions to the user:

    • chmod u+rw filename
    • This command gives the owner (user) of the file read and write permissions.
  • Remove execute permission from the group:
    • chmod g-x filename
    • This command removes execute permission for the group associated with the file.
  • Set read-only permissions for everyone:
    • chmod a=r filename
    • This command sets the file to be read-only for the user, group, and others.

Intermediate chmod Commands:

  • Grant execute permission to the user and the group:
    • chmod ug+x filename
    • This command adds execute permission for both the user and the group.
  • Set specific permissions using numeric mode:
    • chmod 755 filename
    • This command sets the permissions to read, write, and execute for the user, and read and execute for the group and others.
  • Set different permissions for a directory and its contents:
    • chmod -R 644 directory/
    • This command sets read and write permissions for the user, and read-only permissions for the group and others, recursively for all files in the directory. Directories themselves will have read and execute permissions for all.

Advanced chmod Commands:

  • Set the setuid bit:
    • chmod u+s filename
    • This command sets the setuid bit, allowing users to execute the file with the permissions of the file owner.
  • Set the setgid bit on a directory:
    • chmod g+s directory/
    • This command sets the setgid bit on a directory, causing new files created within the directory to inherit the group ID of the directory.
  • Set the sticky bit on a directory:
    • chmod +t directory/
    • This command sets the sticky bit on a directory, which ensures that only the file owner, directory owner, or root can delete or rename the files within the directory.

These commands illustrate the flexibility and power of the chmod command in managing file permissions, ranging from basic to advanced usage scenarios.


You should also read:

chmod command

Please give and explain 10 examples of the chmod command. The chmod command in Unix and Unix-like operating systems is used to change…

chmod command

Kobie is a RHEL System Administrator at Google. He is studying for his LFCS exam. He wants to master the chmod command. Please…