How Check Permissions of a File in Linux

How Check Permissions of a File in Linux

If you want to know how check permissions of a file in linux, the quickest method is to use ls -l. For more detail, use stat. These commands show who can read, write, or execute the file, along with the owner, group, and any special permission bits. If ACLs are involved, use getfacl as well.

How to check file permissions in Linux

How to check file permissions in Linux

The simplest way to inspect permissions is to list the file in long format. This shows the permission string at the start of the line.

ls -l filename

Example output:

-rw-r--r-- 1 alice dev  2048 Oct 10 09:15 notes.txt

In this example, the first part, -rw-r–r–, is the permission string. It tells you the file type and what access is allowed for the owner, group, and others.

Use ls -l to view permissions

Use ls -l to view permissions

ls -l is the most common command for checking file permissions because it is fast and easy to read. The format usually looks like this:

ls -l /path/to/file

The output is broken into parts:

  • First character: file type, such as - for a regular file or d for a directory
  • Next 9 characters: permissions for owner, group, and others
  • Owner: the user who owns the file
  • Group: the group assigned to the file
  • Size and timestamp: file metadata, not permissions

For a directory, the output may look like this:

drwxr-xr-x 2 alice dev 4096 Oct 10 09:20 project

Here, the leading d means directory, not a regular file.

Use stat for detailed permission info

stat provides a more detailed view than ls -l. It is useful when you want both the symbolic mode and the numeric mode.

stat filename

Example output includes lines like these:

Access: (0644/-rw-r--r--)  Uid: ( 1000/ alice)   Gid: ( 1000/ dev)

This is especially helpful because it shows the numeric permission mode, such as 644 or 755, alongside the symbolic form.

When to use ls and when to use stat

When to use ls and when to use stat
CommandBest forWhat you get
ls -lQuick visual checkReadable permission string, owner, group
statDetailed inspectionSymbolic mode, numeric mode, timestamps, inode details
getfaclACL inspectionExtra access rules beyond standard Unix permissions

How to read rwx and numeric modes

How to read rwx and numeric modes

Linux file permissions are usually shown as three groups of three characters:

rwxr-xr--

Each group means something different:

  • Owner permissions: first three characters
  • Group permissions: middle three characters
  • Others permissions: last three characters

The letters mean:

  • r = read
  • w = write
  • x = execute
  • – = permission not granted

For example:

-rw-r--r--

This means:

  • Owner can read and write
  • Group can read only
  • Others can read only

Numeric modes are another way to express the same permissions. Common examples include:

  • 644 = owner read/write, group read, others read
  • 755 = owner read/write/execute, group read/execute, others read/execute
  • 700 = owner full access, no access for group or others

The numeric mode is based on values assigned to each permission:

  • r = 4
  • w = 2
  • x = 1

Add the values for each category. For example, rw- = 4 + 2 = 6, r– = 4, and r-x = 4 + 1 = 5. That is why rw-r–r– becomes 644.

Owner, group, and others explained

Every regular Linux permission set has three access classes:

  • Owner, the user who owns the file
  • Group, users who belong to the file’s group
  • Others, everyone else on the system

This is why the same file can allow different actions for different users. A file may be writable by the owner but read-only for everyone else.

If you need to know which user or group owns the file, both ls -l and stat show that information clearly.

Special permissions to watch for

Sometimes a file shows more than the standard rwx pattern. Special permission bits can appear in the execute positions:

  • setuid, shown as s or S in the owner’s execute slot
  • setgid, shown as s or S in the group’s execute slot
  • sticky bit, shown as t or T in the others execute slot

Examples:

-rwsr-xr-x
drwxrwxrwt

These bits matter because they change how a file or directory behaves. For example, the sticky bit on a shared directory helps prevent users from deleting files they do not own.

If you only need to check basic read, write, and execute access, ls -l is usually enough. If the permission string contains s, S, t, or T, pay attention, because the file has special behavior.

Check directory permissions

Directories use the same permission letters, but their meaning is slightly different. With directories:

  • read means you can list the directory contents
  • write means you can create, remove, or rename entries
  • execute means you can enter the directory and access items inside it

This means a directory can be readable but not enterable, or enterable but not listable, depending on the permission set.

Example:

dr-x------ 2 alice dev 4096 Oct 10 10:00 reports

In this case, the owner can read and enter the directory, but no one else has access.

Quick examples

Example 1: common text file

ls -l report.txt
-rw-r--r-- 1 alice dev 1200 Oct 10 09:15 report.txt

Meaning, the owner can read and write, and everyone else can only read.

Example 2: executable script

ls -l backup.sh
-rwxr-xr-x 1 alice dev  845 Oct 10 08:40 backup.sh

Meaning, the owner can read, write, and execute the script. Group and others can read and execute it too.

Example 3: detailed mode with stat

stat backup.sh

You might see output similar to:

Access: (0755/-rwxr-xr-x)

This confirms the symbolic permissions and the numeric mode in one line.

Common mistakes

  • Confusing files and directories, because execute means something different for each
  • Forgetting ownership, since permissions are checked against owner, group, and others in that order
  • Ignoring ACLs, which can add permissions that do not appear in ls -l
  • Reading numeric modes incorrectly, especially when special bits are present
  • Assuming write access means delete access, which is not always true for directories with the sticky bit

What if ACLs are set?

Standard Linux permissions may not tell the full story if Access Control Lists, or ACLs, are in use. ACLs can grant additional access to specific users or groups beyond the basic owner, group, and others model.

To inspect ACLs, use:

getfacl filename

If a file has ACLs, this command shows the extra rules. This is the best next step when ls -l does not seem to explain why a user can or cannot access a file.

Practical decision guide

  • Use ls -l when you want a quick permission check
  • Use stat when you want detailed metadata and numeric modes
  • Use getfacl when basic permissions do not explain access behavior

Frequently Asked Questions About how check permissions of a file in linux

How do I check the permissions of a file in Linux?

Use ls -l filename for a quick view, or stat filename for a more detailed result. Both commands show the file’s permission settings.

What command shows file permissions in Linux?

ls -l is the most common command. If you need numeric mode and extra details, use stat.

What does rw-r–r– mean in Linux?

It means the owner can read and write, while the group and others can only read. In numeric form, it is usually 644.

How do I check permissions for a directory in Linux?

Use ls -ld directoryname or stat directoryname. The permission bits work the same way, but directory read, write, and execute have directory-specific meanings.

How do I see ACLs on a file in Linux?

Use getfacl filename. ACLs can add permission rules that are not visible in the standard ls -l output.

How can I tell if a file is executable?

Look for an x in the permission string, such as -rwxr-xr-x. You can also confirm with stat.

Why do special permission bits matter?

Setuid, setgid, and sticky bit change how access works beyond basic read, write, and execute permissions. They are important when a file or directory behaves differently than expected.

Conclusion

If you need to know how check permissions of a file in linux, start with ls -l. It gives you the fastest readable view of the permission string, owner, and group. Use stat when you want a more detailed breakdown, and use getfacl if standard permissions do not explain the access rules. Once you can read rwx strings and numeric modes, checking Linux file permissions becomes quick and straightforward.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *