Check file permission in Ubuntu
How To

How to Check File Permissions in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

So you were on your way to executing a file and suddenly got an error saying "Permission denied"

permission denied in Ubuntu

In that case, the chances of you were not allowed to access the file are pretty high.

The usual way to see the file permission is to use the long listing option with ls command:

Ubuntu 18.04 Review of New Features
Ubuntu 18.04 Review of New Features
ls -l filename

But you need to understand the concept of file permission and ownership to actually understand its meaning.

use ls command in ubuntu to check file permission

Another way check the file permission in ubuntu is to use the getfacl utility:

getfacl filename
how to check file permission in Ubuntu

There are other methods to check file permissions but before that, let's understand file permission in Linux.

Understanding file permissions in Ubuntu

Linux by its nature gives the ability to have multiple users in a single system and that came with the threat as any other user can access your sensitive documents.

And this is where the file permissions come to save you.

So there are 3 types of ownership in Linux:

  • User ownership.
  • Group ownership.
  • Others.

While there are 3 types of permission in Linux:

  • Read (r).
  • Write (w).
  • Execute (x).

For better understanding, let's take an example of the ls command:

use ls command in ubuntu to check file permission

So you get a sequence of permission but how you are supposed to know which is for the user and which is for group users? Well, here's the illustration:

File permissions in linux explained

So now you know the basics, let's have a look at multiple methods by which you can check file permissions.

Check file permission in Ubuntu

In this guide, I'm going to share 3 ways by which you can check for file permissions in Linux. So let's start with the widely used one.

Using the ls command

The ls command is generally used to list files in a specific directory but you can also use it to get additional info such as file permissions.

To check file permissions using, you'd need to pair the ls command with the -l option.

ls -l
how to check file permissions in ubuntu using the ls command

Similarly, you can also use -a option to show hidden files:

ls -la
how to list hidden files in ubuntu using ls command

And if you want to know what each element in the above output stands for, I'd recommend checking the other guide of ours:

Linux File Permissions and Ownership Explained with Examples
Linux file permissions explained in simpler terms. Also learn how to change the file permissions and ownership in Linux in this detailed beginner’s guide.

Using stat command

While the ls command gave me the list of files with read-write permission attached to each one, the stat command requires a file name as it gets even more details than the ls command.

To list file details, you just have to pair the filename with the stat command:

stat a.sh 
use stat command to get file details in ubuntu

But if you are someone like me who prefers only necessary details, the stat command allows users to modify the output with the --format option:

stat --format "R/W/E permissions: %A, Group owner: %G, User owner: %U" a.sh
use stat command with variables to get specific info in ubuntu

Here, I've used 3 variables with text attached to them making them more relevant:

  • %A shows file permission.
  • %G gets the name of the group owner.
  • %U will show the user owner.

Using the getfacl utility

This is my favorite utility when it comes to checking file permissions in Linux. And it comes pre-installed in Ubuntu too!

The reason why it is my favorite is that it only shows the necessary details and conveniently presents details.

Pair the filename with the getfacl utility and that's it:

getfacl filename
use getfacl command to check file permissions in Ubuntu

Wrapping Up

This was my take on how you can check file permissions in Ubuntu with some basics. And if you want to know how change the permission, use the chmod command.

chmod 777 or 755? Learn to use chmod Command with Examples
This article will teach you how to change permissions in Linux with practical examples of chmod command.