Permission Shortcuts | Linux

2024/01/19

In Linux, Permission Shortcuts are a convenient notation used to set permissions on files or directories. These shortcuts typically use letters or symbols, making it easy for users to quickly configure the desired permissions.

Common Linux Permission Shortcuts and Their Meanings:

  1. r- Read Permission: Allows reading the contents of a file or viewing the contents of a directory.
  2. w- Write Permission: Allows modifying the contents of a file or creating and deleting files within a directory.
  3. x- Execute Permission: For files, it means the file can be executed; for directories, it means you can enter the directory.
  4. -- No Permission: Indicates that the corresponding permission is not set.

These permission shortcuts can be combined to set multiple permissions at once. Here are some examples:

  • rwx : The owner has read, write, and execute permissions.
  • rw- : The owner has read and write permissions, but no execute permission.
  • r-- : The owner has read permission only, with no write or execute permissions.
  • --- : No permissions at all.

Usage Examples:

You can use the chmod command with permission shortcuts to set permissions on files or directories. Here are some examples:

sudo chmod 777 file.txt
# The above command is equivalent to the following: it grants the highest permissions to everyone
sudo chmod u=rwx,g=rwx,o=rwx file.txt
# Regardless of the environment or user you are in, we never recommend giving any file 777 permissions
# Because doing so makes your Linux permission management dangerous; it is not recommended to assign file permissions this way

touch new-program
# Add execute permission for user, group, and other
chmod +x new-program
# Remove execute permission for user, group, and other
chmod -x new-program

# Add write permission for user, group, and other
chmod +w new-program
# Remove write permission for user, group, and other
chmod -w new-program

# Add read permission for user, group, and other
chmod +r new-program
# Remove read permission for user, group, and other
chmod -r new-program
  • In 777:
    • The first digit represents: user permissions (user)
    • The second digit represents: group permissions (group)
    • The third digit represents: permissions for others or other groups (other)
  • read (r): worth 4 points
  • write (w): worth 2 points
  • execute (x): worth 1 point
  • Common numeric meanings:
    • Number 7 means: 4+2+1 => rwx (read, write, execute)
    • Number 6 means: 4+2 => rw (read, write)
    • Number 5 means: 4+1 => rx (read, execute)
    • Number 4 means: 4 => r (read)
    • Number 2 means: 2 => w (write)
    • Number 1 means: 1 => x (execute)
    • Number 0 means: no permissions at all