File Permissions in Linux

File Permissions in Linux

Permissions determine the ways different users can interact with a file or directory. When listing a file with the ls -l command, the output includes permission information. For the example we will use a script called hello.sh located in the Documents directory:

File Type Field

The first character of this output indicates the type of a file. Recall that if the first character is a -, this is a regular file. If the character was a d , it would be a directory.

Permissions Field

After the file type character, the permissions are displayed. The permissions are broken into three sets of three characters.

Owner

The first set is for the user who owns the file. If your current account is the user owner of the file, then the first set of the three permissions will apply and the other permissions have no effect. The user who owns the file, and who these permissions apply to, can be determined by the user owner field:

Group

The second set is for the group that owns the file. If your current account is not the user owner of the file and you are a member of the group that owns the file, then the group permissions will apply and the other permissions have no effect. The group for this file can be determined by the group owner field:

Permission Types

There are three different permissions that can be placed on a file or directory: read, write, and execute. The manner in which these permissions apply differs for files and directories, as shown in the chart below:

PermissionEffects on FileEffects on Directory
read (r)Allows for file contents to be read or copied.Without execute permission on the directory, allows for a non-detailed listing of files. With execute permission, ls -l can provide a detailed listing
write (w)Allows for contents to be modified or overwritten. Allows for files to be added or removed from a directory.For this permission to work, the directory must also have execute permission.
execute (x)For this permission to work, the directory must also have execute permission.Allows a user to change to the directory if parent directories have execute permission as well.
Leave a Reply
Your email address will not be published. *

This site uses Akismet to reduce spam. Learn how your comment data is processed.