🧱 Detailed Explanation of Linux File Attributes
📘 Understanding file attributes and permissions is the first step in mastering Linux system administration.
👥 1. Linux is a Multi-User System
Linux is a typical multi-user operating system. Different users have different system permissions. To ensure system security, Linux has strict rules regarding “who can access which files and what operations can be performed”.
Common modification commands include:
-
🧩
<span>chown</span>: Change the owner or group of a file. -
🔐
<span>chmod</span>: Change the access permissions of a file. -
🧱 chgrp: Change the group
🔍 2. Viewing File Attributes
Use the command:
ls -l
Example output:
dr-xr-xr-x 2 root root 4096 Dec 14 2012 bind
-r-xr-xr-x 4 root root 4096 Apr 19 2012 boot
Explanation as follows:
-
The first character
<span>d</span>indicates the file type: -
<span>d</span>: Directory -
<span>-</span>: Regular file -
<span>l</span>: Link file -
<span>b</span>: Block device (random access) -
<span>c</span>: Character device (e.g., keyboard, mouse) -
The next 9 characters are divided into three groups (
<span>rwx rwx rwx</span>): -
r: Read (read) → Value is 4
-
w: Write (write) → Value is 2
-
x: Execute (execute) → Value is 1
-
If there is no permission, it is represented by
<span>-</span>.
🧩 3. Structure of File Permissions
A file’s permissions consist of 10 characters, for example:
d rwx r-x r-x
Meaning explanation:
Position 0: Indicates file type (d for directory, - for regular file)
Positions 1–3: Owner's (owner) permissions
Positions 4–6: Group's (group) permissions
Positions 7–9: Other users' (others) permissions
Positions without permissions are displayed as -
👤 4. File Owner and Group
In Linux, each file has:
-
Owner (owner): The file’s owner;
-
Group (group): The user group to which the file belongs.
For example:
drwxr-xr-x 3 mysql mysql 4096 Apr 21 2014 mysql
Explanation:
-
Owner is
<span>mysql</span> -
Group is
<span>mysql</span> -
Owner has read, write, and execute permissions;
-
Group users have read and execute permissions;
-
Other users have read and execute permissions.
💡 Tip:
<span>root</span>user is almost unrestricted and can access any file.
🔧 5. Changing File Attributes
1️⃣ Change Group: (<span><span>chgrp</span></span>)
Command format:
chgrp [-R] group_name file_name
-R: Recursively change the group of subdirectories and files.
Example:
chgrp users example.txt
2️⃣ Change Owner: (chown) Command format:
chown [-R] username file_name
chown [-R] username:group_name file_name
Example:
chown bin install.log
chown root:root install.log
🔧 6. Changing Permissions (<span><span>chmod</span></span>)
Linux permissions consist of three types of identities:
-
👤 owner (file owner)
-
👥 group (file group)
-
🌍 others (other users)
Each identity has r / w / x three permissions.
For example:
-rwxrwx---
Then:
-
owner = 7 (4+2+1)
-
group = 7 (4+2+1)
-
others = 0 → Permission number: 770
Command format:
chmod [-R] 770 file_name
Example:
chmod 777 .bashrc
chmod 754 test.sh
🧠 7. Symbolic Representation
Identity representation:
-
<span>u</span>: Owner (user) -
<span>g</span>: Group (group) -
<span>o</span>: Other users (others) -
<span>a</span>: All users (all)
Permission representation:
-
<span>r</span>: Read (read) -
<span>w</span>: Write (write) -
<span>x</span>: Execute (execute)
Example operations:
-
Set permissions:
chmod u=rwx,g=rx,o=r test1
-
Remove all execute permissions:
chmod a-x test1
🧰 8. Practical Case Illustrations
Example 1: Change in Numeric Permissions
# Initial state
-rw-r--r-- 1 root root 0 Nov 15 10:32 test.sh
# Change permissions to 755
chmod 755 test.sh
# State after change
-rwxr-xr-x 1 root root 0 Nov 15 10:32 test.sh
Change explanation:
-
Owner gains execute permission
-
Group and other users gain execute permission
Example 2: Change in Symbolic Permissions
# Initial state
-rwxrwxrwx 1 root root 0 Nov 15 10:32 test1
# Remove all execute permissions
chmod a-x test1
# State after change
-rw-rw-rw- 1 root root 0 Nov 15 10:32 test1
Change explanation:
-
Removed execute permission (x) for everyone
🔢 Common Permission Number Reference
-
<span><span>777</span></span>→ Everyone can read, write, and execute (⚠️ Lowest security) -
<span><span>755</span></span>→ Owner can read, write, and execute; others can only read and execute (✅ Commonly used for scripts and directories) -
<span><span>700</span></span>→ Only the owner can read, write, and execute (🔒 Commonly used for private files and key directories) -
<span><span>644</span></span>→ Owner can read and write; others can only read (📄 Commonly used for text files) -
<span><span>600</span></span>→ Only the owner can read and write (🔑 Commonly used for password files and configuration files) -
<span><span>400</span></span>→ Only the owner can read (🧩 Critical configuration files to prevent accidental changes) -
<span><span>000</span></span>→ No permissions for anyone (🚫 Access denied)
💡 Tips for Understanding Permissions
-
The larger the number, the higher the permissions.
-
The first number represents the owner, the second represents the group, and the third represents others.
-
Owner 7 =
<span>rwx</span> -
Group 5 =
<span>r-x</span> -
Others 4 =
<span>r--</span>
-
Example:
<span>chmod 754</span>
Recommended Practices:
-
Regular files:
<span>644</span> -
Executable files:
<span>755</span> -
Private files:
<span>600</span> -
Private directories:
<span>700</span>
✅ Summary and Recommendations
The file permission mechanism in Linux is the cornerstone of system security. Understanding permission numbers and symbols, and proficiently using
<span>chown</span>,<span>chgrp</span>, and<span>chmod</span>will enable you to:
✅ Quickly understand the file permission structure✅ Flexibly control access and security policies✅ Avoid system risks caused by accidental operations