Sobes.tech
Junior — Middle

How to set permissions for a file in Linux operating system?

sobes.tech AI

Answer from AI

In Linux, the chmod command is used to set permissions on a file.

Permissions are divided into three categories:

  • Owner (user)
  • Group (group)
  • Others (others)

Each category can be granted rights:

  • Read (r)
  • Write (w)
  • Execute (x)

Examples of setting permissions:

  1. Set read, write, and execute rights for the owner, and only read for group and others:
chmod 744 filename
  1. Add execute permission for all:
chmod a+x filename
  1. Remove write permission for the group:
chmod g-w filename

To view current permissions, use the command:

ls -l filename

Thus, chmod allows flexible management of file access in Linux.