185

I want to know how to see the permissions a particular file has. Which command should I type in the terminal? However, I don't want to change it.

CENTAUR
  • 3,409

4 Answers4

244

If you want to see the permissions of a file, you can use the ls -l /path/to/file command.

For example

> ls -l acroread 
-rwxr-xr-x 1 10490 floppy 17242 May  8  2013 acroread

What does output mean ?

The first column gives you a hint of the type of this object. It can have the following values:

  • - (regular file)
  • d (directory)
  • c (character device)
  • l (symlink)
  • p (named pipe)
  • s (socket)
  • b (block device)
  • D (door)

Then the permissions follow:

  • r means read permission.
  • w means write permission.
  • x means executable permission.
  • - means the permission is not set.

  • The first combination of rwx represents the permissions for the owner.
  • The second combination of rwx represents the permissions for the group.
  • The third combination of rwx represents the permissions for others.

Octal notation

These permissions can also be represented in octal notation:

  • Read permission, or r, is represented by the number 4
  • Write permission, or w, is represented by 2
  • Execute permission, or x, is represented by 1

The sum of these numbers denotes the permission.

The stat command can be used to view file permission in octal notation:

> stat -c "%a %n" /path/of/file

For example:

> stat -c "%a %n" acroread 
755 acroread

Here you can see the following permissions:

  • For the owner they are 4+2+1=7 (111 in binary),
  • for the group they are 4+0+1=5 (101 in binary), and
  • for others they are 4+0+1=5 (101 in binary).
g_p
  • 19,044
  • 6
  • 59
  • 69
41

You can use either long listing:

ls -l [filename]

Or stat:

stat [filename]

Stat is more comprehensive; it shows you the access, modify and change times, as well as Inode and size information, which may or may not be useful to you.

  • 1
    Note: "it depends", that command will show standard permissions, however, your access can be limited by other means, acl, apparmor, and selinux can all limit access outside of what is shown by ls -l . – Panther Sep 25 '14 at 16:51
17

Regardless of your actually using ACL permissions, if you have the acl package installed, you can use getfacl <path> to get a pretty decent breakdown of permissions on that file.

$ getfacl /root/
# file: root/
# owner: root
# group: root
user::rwx
group::---
other::---

If you do use ACL permissions, it'll tell you about permissions that ls and stat just can't.

$ sudo setfacl -m u:oli:r /root
$ getfacl /root/
# file: root/
# owner: root
# group: root
user::rwx
user:oli:r--
group::---
mask::r--
other::---
g_p
  • 19,044
  • 6
  • 59
  • 69
Oli
  • 299,936
0

You can also see file permission by right-clicking the file and selecting properties and there you will find permissions.