CloudsArk
Commands Linux

What Is the chmod Command in Linux?

Learn what the chmod command does in Linux, how its syntax works, and when to use it.

What Is the chmod Command in Linux?

Introduction

The chmod command changes file and directory permission bits. It is useful for beginners, Linux administrators, DevOps engineers, and RHCSA students because it solves practical terminal tasks.

What the Command Does

Use chmod to work with the specific Linux object it manages. Before changing anything, identify the target and run a read-only check when possible.

Basic Syntax

chmod MODE FILE

The syntax includes the command, any options, and the target object.

Common Options

  • -R: apply the mode recursively.
  • -v: print each file that changes.
  • --reference=FILE: copy permissions from another file.

Practical Examples

chmod 644 app.conf
chmod 755 script.sh
chmod -R g+rw /srv/project
find /srv/project -type f -exec chmod 640 {} \;

Verification command:

ls -l app.conf

Example output:

-rw-r--r-- 1 admin admin 742 May 30 10:00 app.conf

When to Use This Command

Use chmod when a file has the wrong read, write, or execute permissions. Common examples include making scripts executable, locking down private configuration files, and fixing shared project directories.

Common Mistakes

  • Using chmod -R 777 to work around access problems instead of fixing ownership or group membership.
  • Applying one recursive mode to both files and directories; files often need 644 while directories need 755.
  • Forgetting that directory execute permission is required to enter or traverse a directory.

Quick Reference

chmod 644 app.conf
chmod 755 script.sh
ls -l app.conf

Summary

The chmod command is safest when you understand the target, choose the right option, and verify the result with a separate command.