Commands.page Logo

How to Check Directory Permissions in Ubuntu

This article provides a concise guide on verifying the permissions of a specific system directory within the Ubuntu operating system. It covers the primary command-line tools required to inspect ownership and access rights, ensuring you can quickly assess security settings without navigating complex menus.

Using the LS Command

The most common way to check directory permissions is using the ls command with specific flags. Open your terminal and type the following command, replacing /path/to/directory with the actual directory path you wish to inspect:

ls -ld /path/to/directory

The -l flag provides a long listing format, while -d ensures you see the permissions of the directory itself rather than its contents. The output will start with a string like drwxr-xr-x. The first character indicates the type (d for directory), followed by three sets of permissions for the owner, group, and others.

Understanding the Output

The permission string is divided into four parts. The first character shows the file type. The next nine characters are grouped into threes:

  1. Owner Permissions: The first three characters define what the file owner can do.
  2. Group Permissions: The middle three characters define access for the user group.
  3. Other Permissions: The last three characters define access for everyone else.

A r stands for read, w for write, and x for execute. A - indicates that the permission is not granted. Following the permission string, you will see the owner name and the group name associated with the directory.

Using the Stat Command

For more detailed information, you can use the stat command. This tool provides a comprehensive view of the file status, including access rights in both symbolic and octal format. Run the following command:

stat /path/to/directory

Look for the line labeled “Access:” to see the permissions in octal notation (e.g., 0755) alongside the symbolic representation. This is particularly useful when scripting or configuring precise access controls.

Accessing Restricted Directories

Some system directories require elevated privileges to view their permissions. If you receive a “Permission denied” error, prepend sudo to your command. For example:

sudo ls -ld /etc/shadow

Using sudo grants you temporary root access, allowing you to inspect protected system folders securely. Always exercise caution when modifying permissions in these areas to maintain system stability.