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.
-
If this is not a duplicate, please mark this as Protected. This is an important question. – Sandun Jul 22 '19 at 21:14
4 Answers
If you want to see the the permission of a file you can use ls -l /path/to/file command.
For example
ls -l acroread
-rwxr-xr-x 1 10490 floppy 17242 May 8 2013 acroread
What does this mean ?
First - represents a regular file. It gives you a hint of the type of object it is.
It can have following values.
- d (directory)
- c (character device)
- l (symlink)
- p (named pipe)
- s (socket)
- b (block device)
- D (door)
- - (regular file)
r represents read permission.
w represents write permission and
x represents executable permission.
First combination of rwx represents permission for the owner .
Second combination of rwx represents permission for the group .
Third combination of rwx represents permission for the other of the file.
Octal notation
Permission of file can also be represented in octal notation.
In octal notation
Read or r is represented by 4,
Write or w is represented by 2
Execute x is represented by 1.
Sum of these three is use to represent the permission.
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
For owner it is 4+2+1=7 (111 in binary)
For group it is 4+0+1=5 (101 in binary) and
For other it is 4+0+1=5 (101 in binary).
- 18,154
- 6
- 56
- 69
-
1
-
What is input, and what is output here? What is the meaning of all the unmentioned things in the output? Speaking especially of the `1` and the `10490` and the `floppy` and the `17242`. I can make sense of the `May 8 2013`, it is the creation date, formatted, I assume. Also, what is the meaning of the `-c` and the `%a` and the `%n` in the stat command? – Nils Lindemann Jul 08 '23 at 22:25
-
@NilsLindemann question is not about the interpretation of `ls` output but about file permission and I think all the answers here explain it very well. – g_p Jul 10 '23 at 06:34
-
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.
- 491
- 3
- 4
-
1Note: "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
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::---You can also see file permission by right-clicking the file and selecting properties and there you will find permissions.
- 352
- 1
- 7
- 22