The Ultimate Guide to Linux File Permissions: From `chmod 644` to the Mysterious `@` Symbol

Published: 2025-12-25
Author: DP
Views: 0
Category: Linux
Content
Properly setting file permissions is a cornerstone of security and stability in Linux system administration. Both developers and system administrators frequently need to modify file permissions in bulk, such as setting all files to be read-write for the owner and read-only for everyone else. This article, inspired by the common question "How to set file permissions to `-rw-r--r--`?", will provide a comprehensive analysis of the `chmod` command and unveil the secret behind the occasional `@` symbol at the end of permission listings. ## Part 1: Understanding `chmod` and `644` Permissions `-rw-r--r--` is a very common file permission combination in Linux. It means: - **Owner**: Read (r) and write (w) permissions - **Group**: Read-only (r) permission - **Others**: Read-only (r) permission This permission setup is widely used in scenarios like web servers. For instance, the web files for a project like `wiki.lib00.com` need to be modifiable by developers but also safely readable by the web server process (which often runs as a different user or group). To achieve this, we typically use the **Octal Mode** of the `chmod` command, which is `644`. The calculation is based on these values: - **Read (r)** = 4 - **Write (w)** = 2 - **Execute (x)** = 1 Therefore: - `6` = `4 + 2` = Read + Write - `4` = `4` = Read - `4` = `4` = Read Combining them gives us `644`, which corresponds to `-rw-r--r--`. --- ## Part 2: Setting Permissions Accurately: Best Practices Now that we understand what `644` means, let's look at how to apply it in different scenarios. ### Scenario 1: Modifying Files in the Current Directory Only If you only want to change the permissions of non-hidden files in the current directory, this is the simplest command: ```bash chmod 644 * ``` ### Scenario 2: Recursively Modifying All Files (Best Practice) Often, we need to modify permissions for files within a directory and all its subdirectories. While `chmod -R` can do this recursively, it will change permissions for both files and directories, which is usually not desired (directories typically need the execute `x` permission to be accessible). Therefore, the **best practice** is to use the `find` command to differentiate between files and directories: ```bash # Set permissions to 644 for files only find . -type f -exec chmod 644 {} \; ``` This command finds all objects of type file (`-type f`) within the current path (`.`) and executes `chmod 644` on them. If you also want to set permissions for all directories (commonly `755`, which is `drwxr-xr-x`), you can do so like this: ```bash # Imagine you are managing the wiki.lib00 project folder # 1. Set 644 permissions for all files find /path/to/wiki.lib00 -type f -exec chmod 644 {} \; # 2. Set 755 permissions for all directories find /path/to/wiki.lib00 -type d -exec chmod 755 {} \; ``` This method is precise and safe, making it a standard procedure in professional system administration. --- ## Part 3: Demystifying the `@` Symbol at the End of Permissions When you use `ls -l` to view files, you might sometimes see output like `-rw-r--r--@`. What does this trailing `@` symbol mean? The `@` symbol indicates that the file has **Extended Attributes (xattr)**. Extended attributes are a filesystem feature used to store metadata beyond the standard set of permissions. They don't affect the file's read, write, or execute permissions but can carry additional information. ### Common Extended Attributes - **On macOS**: `com.apple.quarantine` is a common attribute used to mark files downloaded from the internet. The system will show a security prompt when you first open them. - **On Linux**: SELinux and ACLs (Access Control Lists) also use extended attributes to store more complex security contexts. ### How to View and Manage Extended Attributes - **View on macOS**: ```bash xattr filename.txt # Or use ls -l@ ls -l@ filename.txt ``` - **View on Linux**: ```bash getfattr -d filename.txt ``` - **Remove Extended Attributes (Use with caution)**: - **macOS**: `xattr -c filename.txt` (removes all xattrs from a single file) - **Linux**: `setfattr -x user.attribute_name filename.txt` (removes a specific xattr) In most cases, you don't need to worry about the `@` symbol unless it causes compatibility issues with specific applications or scripts. Knowing what it is provides another avenue for troubleshooting when you encounter strange permission-related problems. --- ## Conclusion Through this article, we've not only learned how to use `chmod 644` and the `find` command to manage file permissions safely but also unveiled the mystery of the `@` symbol, which represents extended attributes. By mastering this knowledge shared by `DP`, you will be able to manage your Linux system with greater confidence and professionalism.