Understanding File Permissions in Linux
Linux file permissions control who can read, write, or execute files.
Viewing Permissions
Use the `ls -l` command to view permissions. The output looks like `-rwxrw-r--`.
- The first character indicates the file type (`-` for file, `d` for directory).
- The next three characters (`rwx`) are for the Owner.
- The next three (`rw-`) are for the Group.
- The final three (`r--`) are for Others (everyone else).
Changing Permissions with `chmod`
You can use numeric or symbolic modes. The numeric mode is common:
- 4 = Read (r)
- 2 = Write (w)
- 1 = Execute (x)
Add the numbers for the permissions you want. For example, `rwx` is 4+2+1=7. `r-x` is 4+1=5.
# Give owner read/write/execute, group read/execute, and others read/execute:
chmod 755 a_file.sh
# Give owner read/write, group read-only, and others read-only (common for web files):
chmod 644 index.html
Copy