Checking File and Directory Permissions
To check the permissions of a file or directory in Linux, you can use the ls
command with the -l
(long listing) option.
ls -l
This will display the permissions, owner, group, size, modification time, and filename for each file and directory in the current directory.
The permissions are displayed in the following format:
-rw-r--r-- 1 user group 1024 Apr 24 12:34 example.txt
The first character indicates the file type:
-
: Regular file
d
: Directory
l
: Symbolic link
The next 9 characters represent the permissions for the owner, group, and others, respectively.
You can also check the permissions of a specific file or directory by providing the path as an argument to the ls -l
command:
ls -l /path/to/file.txt
To get more detailed information about a file or directory, you can use the stat
command:
stat /path/to/file.txt
This will display various metadata about the file, including the permissions, owner, group, and other attributes.
Understanding the ls -l
Output
Let's break down the permissions displayed in the ls -l
output:
Permission |
Meaning |
r |
Read permission |
w |
Write permission |
x |
Execute permission |
- |
No permission |
The permissions are displayed in the following order: owner, group, others.
For example, the permissions rw-r--r--
indicate:
- Owner has read and write permissions
- Group has read permission
- Others have read permission
You can also use the stat
command to get the numerical representation of the permissions:
stat -c "%a %n" /path/to/file.txt
This will display the numerical permissions (e.g., 644
) and the filename.