Execute Permission


Execute Permission (Symbolic and Octal Modes)

The execute permission allows a user to run a file as a program or script. For a directory, the execute permission (also called "search" permission) grants the ability to enter the directory and access files and subdirectories within it. Without execute permission on a directory, its contents are inaccessible, even if you have read permissions.

Symbolic Mode Examples for Execute Permission

Example 1: chmod a+x my_script.pl

# Adds execute permission for all users (user, group, and others).
# a: Represents all users.
# +: The operator that adds a permission.
# x: Signifies the execute permission.
chmod a+x my_script.pl

Explanation This command makes my_script.pl executable (x) by everyone (a) on the system. It is a straightforward way to make a script runnable by any user who has access to it.


Example 2: chmod go-x /home/user/private_tool

# Removes execute permission from the group and others.
# go: Represents both the group and others.
# -: The operator that removes a permission.
# x: Signifies the execute permission.
chmod go-x /home/user/private_tool

Explanation This command removes (-) the execute (x) permission from the group (g) and others (o). This prevents anyone other than the owner from running the private_tool executable, enhancing security and control.


Example 3: chmod u=rwx,go=rx deploy.sh

# Sets full permissions for user, and read/execute for group and others.
# u=rwx: Sets user permissions to exactly read, write, and execute.
# go=rx: Sets group and others permissions to exactly read and execute.
chmod u=rwx,go=rx deploy.sh

Explanation This command sets (=) the owner's permissions to read, write, and execute (rwx). Simultaneously, it sets the group and others (go) to read and execute (rx), a standard configuration for shared scripts that others can run but not modify.


Example 4: chmod -R u+X /opt/app

# Recursively adds execute permission for the user to directories and files that are already executable.
# -R: The recursive flag.
# u: Represents the user.
# +X: Adds execute only if it's a directory or if someone already has execute permission.
chmod -R u+X /opt/app

Explanation The capital X is a special symbolic permission that applies execute rights intelligently. It grants execute permission to directories for directory traversal and to files only if they already have execute permission for the user, group, or others, preventing regular files from accidentally becoming executable.

Octal Mode Examples for Execute Permission

Example 1: chmod 755 /bin/custom_utility

# Sets user to read/write/execute, and group/others to read/execute.
# 7 (4+2+1): User has read, write, and execute.
# 5 (4+1): Group has read and execute.
# 5 (4+1): Others have read and execute.
chmod 755 /bin/custom_utility

Explanation The 755 permission is the quintessential setting for executable programs and scripts intended for system-wide use. It gives the owner full control (7) while allowing all other users to read and execute (5) the utility.


Example 2: chmod 700 /root/admin_script.sh

# Sets read, write, and execute permissions for the user only.
# 7 (4+2+1): User has read, write, and execute.
# 0: Group has no permissions.
# 0: Others have no permissions.
chmod 700 /root/admin_script.sh

Explanation This 700 permission provides the owner with full read, write, and execute access (7). It completely denies access to the group and others, making it a secure choice for administrative scripts that only the root user should run.


Example 3: chmod 111 lockdown_script.sh

# Sets execute-only permission for all users.
# 1: User has execute-only permission.
# 1: Group has execute-only permission.
# 1: Others have execute-only permission.
chmod 111 lockdown_script.sh

Explanation This command grants only the execute (1) permission to the user, group, and others. While uncommon, it can be used for compiled binaries or scripts where you want to prevent users from reading the source code but still allow them to run the program.


Example 4: chmod 550 /srv/share/run_tool

# Sets read/execute for user and group, no permissions for others.
# 5 (4+1): User has read and execute.
# 5 (4+1): Group has read and execute.
# 0: Others have no permissions.
chmod 550 /srv/share/run_tool

Explanation The 550 permission allows the owner and group members to read and execute (5) the file but gives no access (0) to others. This is effective for tools that need to be shared and run by a specific team but kept private from other users on the system.

Command Consistency Across UNIX/Linux Systems

The chmod command, including its symbolic (u,g,o,a,r,w,x) and octal (7,5,5) modes, is defined by the POSIX standard for operating systems. This standardization ensures that the commands and concepts explained here are virtually identical across all modern UNIX and Linux distributions. Whether you are working on RHEL 8, Oracle Solaris, or HP-UX, the syntax and behavior for manipulating read, write, and execute permissions with chmod remain consistent, making it a truly universal administrative skill.