chmod Command Examples in Linux¶
Introduction¶
These examples show practical ways to use chmod on a Linux terminal. Each example is written so you can adapt it for administration or troubleshooting.
Example 1: Basic Usage¶
chmod 644 app.conf
This is the simplest form of the command and is a good starting point before adding options.
Example 2: Common Admin Task¶
chmod 755 script.sh
This example reflects a common task on RHEL, Rocky Linux, AlmaLinux, or similar systems.
Example 3: Useful Option¶
chmod -R g+rw /srv/project
This option helps narrow the result, change behavior, or handle a more realistic target.
Example 4: Real-World Scenario¶
find /srv/project -type f -exec chmod 640 {} \;
Use this pattern when the task moves beyond a single basic command.
Example 5: Verification¶
ls -l app.conf
Example output:
-rw-r--r-- 1 admin admin 742 May 30 10:00 app.conf
Common Mistakes¶
- Using
chmod -R 777to work around access problems instead of fixing ownership or group membership. - Applying one recursive mode to both files and directories; files often need
644while directories need755. - Forgetting that directory execute permission is required to enter or traverse a directory.
Quick Reference¶
chmod 644 app.conf
chmod 755 script.sh
chmod -R g+rw /srv/project
find /srv/project -type f -exec chmod 640 {} \;
ls -l app.conf
Related Guides¶
Summary¶
Good chmod usage means choosing the right option, keeping the target clear, and verifying the result with output you can explain.