ArticleslgStudy

computer science

Chmod

Chmod is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Chmod rather than just read about it. In short: chmod is a shell command for changing access permissions and special mode flags of files (including special files such as directories). The name is short for change mode where mode refers to the permissions and flags collectively.

Key takeaways

  • Chmod belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Chmod to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Chmod from memory before moving on to harder problems.

Reference excerpt

chmod is a shell command for changing access permissions and special mode flags of files (including special files such as directories). The name is short for change mode where mode refers to the permissions and flags collectively. The command originated in AT&T Unix version 1 and was exclusive to Unix and Unix-like operating systems until it was ported to other operating systems such as Windows (in UnxUtils) and IBM i. In Unix and Unix-like operating systems, a system call with the same name as the command, chmod(), provides access to the underlying access control data. The command exposes the capabilities of the system call to a shell user. As the need for enhanced file-system permissions grew, access-control lists were added to many file systems to augment the modes controlled via chmod. The implementation of chmod bundled in GNU coreutils was written by David MacKenzie and Jim Meyering.

Use Although the syntax of the command varies somewhat by implementation, it generally accepts either a single octal value (which specifies all the mode bits on each file), or a comma-delimited list of symbolic specifiers (which describes how to change the existing mode bits of each file). The remaining arguments are a list of paths to files to be modified. Changing permissions is only allowed for the superuser (root) and the owner of a file. If a symbolic link is specified, the target of the link has its mode bits adjusted. Permissions directly associated with a symbolic link file system entry are typically not used.

Options Optional, command-line options may include:

-R recursive; include contained files and subdirectories of specified directories -v verbose; log changed file names

Octal notation Given a numeric permissions argument, the chmod command treats it as an octal number, and replaces all the mode bits for each file. (Although four digits are specified, leading 0 digits can be elided.) There are twelve standard mode bits, comprising three special bits (setuid, setgid, and sticky), and three permission groups (controlling access by user, group, and other) of 3 bits each (read, write, and exec/scan); each permission bit grants access if set (1) or denies access if clear (0). As an octal digit represents a 3-bit value, the twelve mode bits can be represented as four octal digits. chmod accepts up to four digits and uses 0 for left digits not specified (as is normal for numeric representation). In practice, three digits are commonly specified since the special modes are rarely used and the user class is usually specified. In the context of an octal digit, each operation bit represents a numeric value: read: 4, write: 2 and execute: 1. The following table relates octal digit values to a class operations value.

The command stat can report a file's permissions as octal. For example:

The reported value, 754 indicates the following permissions:

user class: read, write, and execute; 7 => (4 + 2 + 1) group class: read and execute; 5 => (4 + 1) others class: read-only; (4) A code permits execution if and only if it is odd (i.e. 1, 3, 5, or 7). A code permits read if and only if it is greater than or equal to 4 (i.e. 4, 5, 6, or 7). A code permits write if and only if it is 2, 3, 6, or 7.

Symbolic notation The chmod command accepts symbolic notation that specifies how to modify the existing permissions. The command accepts a comma-separate list of specifiers like: [classes]+|-|=operations Classes map permissions to users. A change specifier can select one class by including its symbol, multiple by including each class's symbol with no delimiter, or all classes by not specifying a symbol; when using the last method, the bits of the umask mask will remain unchanged. Class specifiers include:

As ownership is key to access control, and since the symbolic specification uses the abbreviation o, some incorrectly think that it means owner, when, in fact, it is short for others. The change operators include:

Operations can be specified as follows:

Most chmod implementations support the specification of the special modes in octal, but some do not which requires using the symbolic notation. The ls command can report file permissions in a symbolic notation that is similar to the notation used with chmod. ls -l reports permissions in a notation that consists of 10 letters. The first indicates the type of the file system entry, such as dash for regular file and 'd' for directory. Following that are three sets of three letters that indicate read, write and execute permissions grouped by user, group and others classes. Each position is either dash to indicate lack of permission or the single-letter abbreviation for the permission to indicate that it's granted. For example:

The permission specifier -rwxr-xr-- starts with a dash, which indicates that findPhoneNumbers.sh is a regular file, not a directory. The next three letters rwx indicate that the file can be read, written, and executed by the owning user dgerman. The next three letters r-x indicate that the file can be read and executed by members of the staff group. And the last three letters r-- indicate that the file is read-only for other users.

Examples Add write permission to the group class of a directory, allowing users in the same group to add files:

Remove write permission for all classes, preventing anyone from writing to the file:

Set the permissions for the user and group classes to read- and execute-only, with no write permission, preventing anyone from adding files:

Enable read and write for the user class while making it read-only for group and others:

See also attrib cacls, modifies access control lists chattr, changes the attributes of a file chgrp, changes the group of a file chown, changes the owner of a file Group identifier – Unix/POSIX system account group number; numeric value used to represent a specific group List of POSIX commands User identifier – Value identifying a user account in Unix and Unix-like operating systems umask, restricts permissions at file creation

Notes

References

External links

chmod(1): change file modes – FreeBSD General Commands Manual chmod(1) – Plan 9 Programmer's Manual, Volume 1 chmod(1) – Inferno General commands Manual chmod — manual page from GNU coreutils. GNU "Setting Permissions" manual CHMOD-Win 3.0 — Freeware Windows' ACL ↔ CHMOD converter. Beginners tutorial with on-line "live" example

Worked examples

Example 1 — a first encounter with Chmod

Start with the simplest possible case. Write down what Chmod claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Chmod before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Chmod ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Chmod

In research
Chmod appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Chmod in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Chmod is common in secondary-school and first-year university syllabi. It links to neighbouring topics File system permissions, IBM i Qshell commands, Inferno (operating system) commands, so understanding it makes those chapters shorter.
In everyday life
Look for Chmod outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Chmod” →

How to study Chmod in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Chmod means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Chmod out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Chmod in simple terms?

chmod is a shell command for changing access permissions and special mode flags of files (including special files such as directories). The name is short for change mode where mode refers to the permissions and flags collectively.

Why does Chmod matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Chmod?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Chmod.

Tags

  • File system permissions
  • IBM i Qshell commands
  • Inferno (operating system) commands
  • Operating system security
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities
  • Unix file system-related software

Keep exploring