Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Bash Dictionary
  3. chmod / chown / chgrp

chmod / chown / chgrp

chmod changes file permissions (access rights), chown changes the owner, and chgrp changes the group. These commands are essential for managing files in a Linux multi-user environment.

Syntax

chmod [options] mode file
chown [options] user[:group] file
chgrp [options] group file

Command / Option List

Command / NotationDescription
chmod 755 fileSets permissions using octal notation (7=rwx, 5=r-x).
chmod +x fileAdds execute permission for all users.
chmod u+x fileAdds execute permission for the file owner (user).
chmod g-w fileRemoves write permission from the group.
chmod o=r fileSets permissions for others to read-only.
chmod -R mode directoryRecursively changes permissions for a directory and its contents.
chown user fileChanges the owner of a file.
chown user:group fileChanges both the owner and group at once.
chown -R user directoryRecursively changes the owner for a directory and its contents.
chgrp group fileChanges only the group of a file.

Sample Code

The following examples use this directory structure.

📁 ~/project/ 📁 public/ 📄 index.html (-rw-r--r--) 📄 deploy.sh (-rw-r--r--) 📄 secret.conf (-rw-rw-rw-)

Add execute permission to a script. This is the most common use case.

chmod +x deploy.sh
ls -l deploy.sh
-rwxr-xr-x 1 user staff 128 Mar  5 10:00 deploy.sh

Set permissions using octal notation. This sets owner to read/write/execute (7), group to read-only (4), and no access for others (0).

chmod 740 secret.conf
ls -l secret.conf
-rwxr----- 1 user staff 256 Mar  5 10:00 secret.conf

Set standard web server permissions.

chmod 644 public/index.html
ls -l public/index.html
-rw-r--r-- 1 user staff 2048 Mar  5 10:00 public/index.html
chmod 755 public/
ls -ld public/
drwxr-xr-x 2 user staff 4096 Mar  5 10:00 public/

Change permissions for all files in a directory at once.

chmod -R 755 public/

Change the owner and group together (requires root privileges).

sudo chown www-data:www-data /var/www/html
ls -ld /var/www/html
drwxr-xr-x 5 www-data www-data 4096 Mar  5 10:00 /var/www/html

Recursively change the owner for a directory and all its contents.

sudo chown -R deploy:deploy /var/www/app

Notes

Octal permission notation is the sum of 4=read (r), 2=write (w), and 1=execute (x). For example, rwxr-xr-x is 755 (7=4+2+1, 5=4+0+1). You can use either symbolic notation (u/g/o with +/-/=) or octal notation — both work, but octal is more explicit and easier to read in scripts.

You can check a file's current permissions and owner with $ ls -l. For detailed metadata, see stat.

If you find any errors or copyright issues, please .