Write Permission


Write Permission (Symbolic and Octal Modes)

The write permission grants the ability to modify, rename, or delete a file. For a directory, write permission allows a user to create, rename, or delete files within that directory, provided the execute permission is also set. It is the key that enables content modification.

Symbolic Mode Examples for Write Permission

Example 1: chmod g+w team_project.doc

# Adds write permission for the group.
# g: Represents the group.
# +: The operator that adds a permission.
# w: Signifies the write permission.
chmod g+w team_project.doc

Explanation This command adds (+) write (w) permission for the group (g) associated with team_project.doc. This is a common action in collaborative environments where multiple team members need to edit a shared file.


Example 2: chmod a-w /etc/hosts

# Removes write permission from all users (user, group, and others).
# a: Represents all users.
# -: The operator that removes a permission.
# w: Signifies the write permission.
chmod a-w /etc/hosts

Explanation This command removes (-) write (w) permission from everyone (a). This is a security measure used to protect critical system files from accidental or unauthorized modification by any user, including the root user.


Example 3: chmod ug=rw,o=r config.ini

# Sets read and write for user/group, but only read for others.
# ug: Represents both user and group.
# =rw: Sets permissions to exactly read and write.
# o=r: Sets permissions for others to exactly read.
chmod ug=rw,o=r config.ini

Explanation This command uses a comma to perform multiple operations at once. It sets (=) the user and group (ug) permissions to read and write (rw), while limiting others (o) to read-only (r), a balanced approach for configuration files.


Example 4: chmod u=w,go= log.txt

# Sets the user permission to write-only and removes all permissions for group and others.
# u=w: Sets user permission to exactly write.
# go=: Sets group and other permissions to nothing.
chmod u=w,go= log.txt

Explanation This is an unusual but valid command that assigns (=) only write (w) permission to the owner (u). It also removes (=) all permissions for the group and others (go), which can be useful for write-only log files or drop-boxes.

Octal Mode Examples for Write Permission

Example 1: chmod 660 shared_document.txt

# Sets read/write for user and group, no permissions for others.
# 6 (4+2): User has read and write permissions.
# 6 (4+2): Group has read and write permissions.
# 0: Others have no permissions.
chmod 660 shared_document.txt

Explanation The 660 permission allows both the owner and the group members to read and write (6) to the file. It completely denies access (0) to others, making it ideal for confidential documents shared within a specific team.


Example 2: chmod 775 /var/www/html/uploads

# Sets read/write/execute for user/group, and read/execute for others.
# 7 (4+2+1): User has read, write, and execute permissions.
# 7 (4+2+1): Group has read, write, and execute permissions.
# 5 (4+1): Others have read and execute permissions.
chmod 775 /var/www/html/uploads

Explanation This permission is often used for directories, such as an uploads folder for a web application. It allows the owner and group (like the web server user) full control (7), while others can list and enter the directory (5) but not create new files.


Example 3: chmod 2770 /srv/group_share

# Sets a directory to be write-only for user, and read/write/execute for group.
# 2: User has write-only permission.
# 7 (4+2+1): Group has read, write, and execute permissions.
# 7 (4+2+1): Group has read, write, and execute permissions.
# 0: Others have no permissions.
chmod 2770 /srv/group_share

Explanation The 2770 permission provides write-only access (2) for the user, full permissions (7) for the group, and no access for others (0). The leading digit is for special permissions; this example focuses on the write permission (2) for the user. This configuration is rare but demonstrates the flexibility of octal mode.


Example 4: chmod 300 write_and_execute_only.sh

# Sets write and execute permissions for the user only.
# 3 (2+1): User has write and execute permissions.
# 0: Group has no permissions.
# 0: Others have no permissions.
chmod 300 write_and_execute_only.sh

Explanation This command grants the owner write (2) and execute (1) permissions, resulting in the octal value 3. It is an unconventional setting, as files are not typically executable without being readable, but it is useful in specific scenarios where a program might write to itself and then run.