File Permissions and Ownership

Understanding File Permissions

File Permissions

In Linux, each file has a set of permissions that determine which users can read, write, or execute the file. These permissions are represented by a series of letters and dashes, such as rwxr-xr-x. The first letter represents the file type, and the remaining letters represent the permissions for the owner, group, and other users.

File Types

There are several different types of files in Linux, including regular files, directories, symbolic links, and device files. The first letter in the file permissions represents the file type. The following table lists the different file types and their corresponding letters:

File TypeLetter
Regular File-
Directoryd
Symbolic Linkl
Device Filec or b

File Permissions

There are three different types of permissions in Linux: read, write, and execute. The remaining letters in the file permissions represent the permissions for the owner, group, and other users. The following table lists the different permissions and their corresponding letters:

PermissionLetter
Readr
Writew
Executex

File Ownership

Each file in Linux has an owner and a group. The owner is the user who created the file, and the group is a collection of users who have access to the file. The owner and group are represented by a username and a group name, respectively.

Changing File Permissions

Changing File Permissions

To change the permissions of a file, use the chmod command. The chmod command takes two arguments: the permissions to set and the file to set them on. The following table lists the different permissions and their corresponding letters:

PermissionLetter
Readr
Writew
Executex

The following table lists the different users and their corresponding letters:

UserLetter
Owneru
Groupg
Othero
Alla

The following table lists the different operations and their corresponding letters:

OperationLetter
Add+
Remove-
Set=

The following table lists some examples of how to use the chmod command:

CommandDescription
chmod u+x filenameAdd execute permission for the owner of the file.
chmod g-w filenameRemove write permission for the group of the file.
chmod o=r filenameSet read permission for other users of the file.
chmod a-x filenameRemove execute permission for all users of the file.

Changing File Ownership

To change the ownership of a file, use the chown command. The chown command takes two arguments: the new owner and the file to change ownership of. The following table lists some examples of how to use the chown command:

CommandDescription
chown user filenameChange the owner of the file to user.
chown user:group filenameChange the owner and group of the file to user and group, respectively.
chown :group filenameChange the group of the file to group.