← Back to Bash Course | Chapter 9: File Testing & Filesystem | Lesson 11 of 13

File Permissions

File permissions are like house rules saying who may read, change or use something. Each file has one set of rules for its owner, one for their group and one for everybody else.

In this page:

  1. File Permissions
Syntax
bash
chmod mode file_name
# e.g. chmod 755 file_name  or  chmod u+x file_name

File Permissions

File permissions control read (r), write (w), and execute (x) access for the owner, group, and others, viewable with ls -l.

chmod changes them, either symbolically (chmod u+x file) or numerically (chmod 755 file). Understanding the numeric mode (owner/group/other as three digits) is essential for managing script and file access.

Note: chmod 755 is the common mode for an executable script: owner can read/write/execute, everyone else can read/execute.

Example: File Permissions

bash
#!/bin/bash
touch demo.sh
chmod 755 demo.sh
ls -l demo.sh

chmod u-x demo.sh
ls -l demo.sh
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using chmod 777 to fix problems, which makes files writable by everyone.
  2. Mixing up the owner, group and others digits in chmod 640.
  3. Forgetting that directories need the execute bit to enter them.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.