πŸ› οΈToolsShed

Chmod Calculator

Calculate Unix file permissions. Convert between octal notation and symbolic rwx format.

Read (r)Write (w)Execute (x)OctalSymbolic
Owner6rw-
Group4r--
Others4r--

Octal

644

Symbolic

rw-r--r--

chmod command

chmod 644 filename

Chmod Calculator helps you understand and generate Unix/Linux file permission settings. In Unix-based systems, every file and directory has a set of permission bits that control who can read, write, or execute it β€” for the owner, the group, and everyone else. The `chmod` command sets these permissions using either symbolic notation (rwx) or octal numbers (e.g., 755).

Toggle the read, write, and execute checkboxes for the Owner, Group, and Others columns, and the tool automatically computes the equivalent octal value and the symbolic string. Conversely, enter an octal value like 644 and the tool shows which permissions are enabled for each user class.

Common permission patterns include 755 (owner can do everything; group and others can read and execute β€” typical for directories and executables), 644 (owner can read and write; others can only read β€” typical for web files), and 600 (only owner can read and write β€” typical for private SSH keys).

Frequently Asked Questions

Code Implementation

import os
import stat

# Set permissions using octal notation
os.chmod('script.sh', 0o755)   # rwxr-xr-x (owner: rwx, group: r-x, others: r-x)
os.chmod('data.txt', 0o644)    # rw-r--r-- (owner: rw-, group: r--, others: r--)
os.chmod('private.key', 0o600) # rw------- (owner: rw-, no access for others)

# Read current permissions
file_stat = os.stat('script.sh')
mode = file_stat.st_mode
print(oct(stat.S_IMODE(mode)))  # e.g. '0o755'

# Check specific permissions using stat constants
is_owner_executable = bool(mode & stat.S_IXUSR)
is_group_readable   = bool(mode & stat.S_IRGRP)
is_others_writable  = bool(mode & stat.S_IWOTH)
print(f"Owner executable: {is_owner_executable}")

# Build permissions programmatically
perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH  # 644
os.chmod('config.ini', perms)

# Recursively set permissions on a directory tree
import pathlib
for path in pathlib.Path('/var/www/html').rglob('*'):
    if path.is_dir():
        os.chmod(path, 0o755)
    else:
        os.chmod(path, 0o644)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.