Command Syntax
The chmod (change mode) command alters file system permissions. Basic terminal syntax is:
chmod [OPTIONS] MODE FILE...Common Command Line Options
| Option | Flag Name | Description & Purpose |
|---|---|---|
-R | Recursive | Apply permission changes recursively to all subdirectories and files inside target directory. |
-v | Verbose | Output a diagnostic message for every processed file. |
-c | Changes | Like verbose, but reports only when a change is actually made. |
--reference=RFILE | Reference | Copy permissions from reference file RFILE instead of specifying octal/symbolic mode manually. |
Practical Command Examples
1. Setting Octal Mode
# Set directory to 755 and file to 644
chmod 755 /var/www/htmlchmod 644 /var/www/html/index.html2. Adding or Removing Specific Permissions (Symbolic)
# Make a shell script executable for the owner
chmod u+x deploy.sh# Remove write access from group and otherschmod go-w document.txt# Grant read access to all userschmod a+r public-readme.txt3. Recursive Bulk Permission Updates
# Recursively fix all directories to 755 without touching files
find /var/www/site -type d -exec chmod 755 +# Recursively fix all regular files to 644 without touching directoriesfind /var/www/site -type f -exec chmod 644 +