How to Check Permissions of a File in Linux
Checking file permissions in Linux is a fundamental skill for anyone working with this operating system. Whether you are managing files on your personal computer or administering a server, understanding who can read, write, or execute a file is crucial. In this article, I’ll guide you through the easiest and most reliable methods to check permissions of a file in Linux.
You’ll discover how to use common commands like ls, stat, and getfacl to view permissions clearly. I’ll also explain what the permission symbols mean and how to interpret them. By the end, you’ll feel confident managing file permissions and ensuring your system stays secure.
Understanding Linux File Permissions
Linux file permissions control who can access or modify files and directories. These permissions are divided into three categories:
- Owner: The user who owns the file.
- Group: A set of users grouped together.
- Others: Everyone else on the system.
Each category can have three types of permissions:
- Read (r): Allows viewing the contents of a file or listing a directory.
- Write (w): Allows modifying or deleting the file or adding/removing files in a directory.
- Execute (x): Allows running a file as a program or entering a directory.
Permissions are shown as a string of 10 characters, such as -rwxr-xr--. The first character indicates the file type (e.g., - for a regular file, d for directory). The next nine characters are split into three groups of three, representing owner, group, and others.
Why Checking Permissions Matters
- Prevent unauthorized access to sensitive files.
- Ensure scripts and programs run correctly.
- Manage shared resources effectively.
- Troubleshoot permission-related errors.
Using the ls -l Command to Check Permissions
The most common way to check file permissions is with the ls -l command. This command lists files in long format, showing detailed information including permissions.
How to Use ls -l
Open your terminal and type:
ls -l filename
Replace filename with the actual file or directory name.
Example Output
-rw-r--r-- 1 user group 4096 Apr 27 12:00 example.txt
Breaking down the output:
-rw-r--r--: File permissions.1: Number of hard links.user: Owner of the file.group: Group owner.4096: File size in bytes.Apr 27 12:00: Last modification date.example.txt: File name.
Interpreting the Permission String
-: Regular file.rw-: Owner can read and write.r--: Group can read only.r--: Others can read only.
Listing Permissions for Multiple Files
You can check permissions for all files in a directory by running:
ls -l
This lists all files with their permissions, owners, and other details.
Using ls -ld for Directories
To check permissions of a directory itself (not its contents), use:
ls -ld directoryname
This shows the directory’s permissions and ownership.
Using the stat Command for Detailed Permission Info
The stat command provides more detailed information about a file, including permissions in both symbolic and numeric formats.
How to Use stat
Run:
stat filename
Example Output
File: example.txt
Size: 4096 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 123456 Links: 1
Access: 2026-04-27 12:00:00.000000000 +0000
Modify: 2026-04-27 12:00:00.000000000 +0000
Change: 2026-04-27 12:00:00.000000000 +0000
Birth: -
Permissions: rw-r--r-- (0644)
What You Learn from stat
- Permissions in symbolic form (
rw-r--r--). - Numeric permissions (
0644), useful for scripting. - File size, inode, and timestamps.
Numeric Permissions Explained
0to7represent permission sets.- Each digit corresponds to owner, group, and others.
- For example,
6means read (4) + write (2) = 6. 4means read only.5means read (4) + execute (1) = 5.
Checking Access Control Lists (ACLs) with getfacl
Sometimes, files have extended permissions called Access Control Lists (ACLs). These allow more fine-grained control beyond the basic owner-group-others model.
What Are ACLs?
ACLs let you specify permissions for individual users or groups. This is useful in complex environments where multiple users need different access levels.
How to Check ACLs
Use the getfacl command:
getfacl filename
Example Output
# file: example.txt
# owner: user
# group: group
user::rw-
user:alice:r--
group::r--
mask::r--
other::r--
This shows:
- Standard permissions.
- Additional user
alicehas read-only access.
When to Use ACLs
- Sharing files with specific users.
- Setting permissions that differ from group settings.
- Managing complex permission requirements.
Using GUI Tools to Check Permissions
If you prefer graphical interfaces, most Linux desktop environments provide file managers that show permissions.
How to Check Permissions in GUI
- Right-click the file or folder.
- Select “Properties” or “Information.”
- Go to the “Permissions” tab.
- View or modify owner, group, and others’ permissions.
Popular File Managers
- Nautilus (GNOME)
- Dolphin (KDE)
- Thunar (XFCE)
GUI tools are user-friendly but may not show ACLs by default.
Tips for Managing File Permissions Safely
Checking permissions is just the first step. Here are some tips to keep your files secure:
- Avoid giving write permission to “others” unless necessary.
- Use groups to manage shared access.
- Regularly audit permissions on sensitive files.
- Use
chmodcarefully to change permissions. - Use
chownto change file ownership when needed. - Consider ACLs for complex permission needs.
Summary Table: Common Permission Commands
| Command | Purpose | Example Usage |
ls -l | List files with permissions | ls -l file.txt |
ls -ld | Show directory permissions | ls -ld /home/user |
stat | Detailed file info and perms | stat file.txt |
getfacl | Show Access Control Lists | getfacl file.txt |
| GUI File Manager | View and edit permissions graphically | Right-click > Properties |
Conclusion
Now you know several ways to check permissions of a file in Linux. The ls -l command is the quickest way to see basic permissions, while stat offers detailed info including numeric modes. For advanced setups, getfacl reveals ACLs that control access beyond the standard model.
Understanding these permissions helps you protect your files and manage access effectively. Whether you use the command line or a GUI, you can now confidently check and interpret file permissions. This knowledge is essential for maintaining security and smooth operation on any Linux system.
FAQs
How do I check permissions of a hidden file in Linux?
Use ls -la to list all files, including hidden ones (those starting with a dot). This shows permissions for hidden files like .bashrc.
What does the permission string -rwxr-xr-- mean?
It means the owner can read, write, and execute; the group can read and execute; others can only read the file.
Can I check permissions of a file I don’t own?
Yes, you can check permissions of any file you have read access to. Use ls -l filename or stat filename.
How do I interpret numeric permissions like 755?
755 means owner has read, write, execute (7), group has read and execute (5), others have read and execute (5).
What command shows extended ACL permissions?
Use getfacl filename to view extended ACL permissions on a file or directory.
