In Unix-like operating systems, the security and privacy of files and directories are governed by a set of permissions. These permissions determine who can read, write, or execute a file or directory. Here’s a guide to understanding, modifying, and viewing these permissions.

Types of Permissions

In Unix and Unix-like systems, there are three basic types of permissions:

  • Read (r): Grants the ability to read the contents of the file or directory.
  • Write (w): Allows the file to be modified or the directory to be altered.
  • Execute (x): Permits the file to be run as a program or the directory to be accessed.

These permissions affect three groups of users:

  • Owner: The user who created the file or directory.
  • Group: Users who are part of the file’s group.
  • Others: Everyone else who is not the owner or part of the group.

The chmod Command

The chmod (change mode) command is used to set or change the permissions of a file or directory. Permissions can be expressed in symbolic or numeric (octal) notation.

Symbolic Notation:

  • chmod u+x file: Adds execute permission for the owner.
  • chmod g-w file: Removes write permission from the group.
  • chmod o=r file: Sets the permissions for others to read only.

Numeric Notation:

  • chmod 755 file: Sets read, write, and execute permissions for the owner; read and execute for the group and others.
  • chmod 644 file: Allows the owner to read and write; others can only read.

Viewing Permissions with ls -la

The ls -la command lists files and directories with detailed information, including their permissions.

Breakdown of ls -la Output:

  1. File Type and Permissions: The first column shows the type and permissions.
  2. Number of Links: How many hard links point to the file.
  3. Owner: Who owns the file.
  4. Group: Which group the file belongs to.
  5. Size: The file’s size.
  6. Modification Date: When the file was last modified.
  7. Filename: The name of the file or directory.

Example:

Here’s how to interpret the ls -la output:

drwxr-xr-x 5 alice staff 4096 Feb 25 14:00 Documents
-rw-r--r-- 1 alice staff 1048576 Feb 25 13:58 report.docx
lrwxrwxrwx 1 alice staff 12 Feb 25 14:02 link_to_report -> report.docx
  • Documents: A directory (d) that the owner can read, write, and execute; the group and others can read and execute.
  • report.docx: A regular file (-) that the owner can read and write; the group and others can only read.
  • link_to_report: A symbolic link (l) pointing to report.docx, accessible by all users.

Conclusion

Understanding and managing file and folder permissions is crucial for maintaining the security and functionality of Unix-like systems. By mastering the chmod command and understanding the ls -la output, users can effectively control access to their files and directories.