Permission

In Linux, file and directory permissions are represented by a 10-character string that specifies the access permissions for the file or directory. Here's what each character in the permission string represents:

-rwxrwxrwx

The first character represents the file type and can be one of the following:

- `-`: regular file

- `d`: directory

- `l`: symbolic link

- `c`: character device file

- `b`: block device file

- `s`: Unix domain socket

- `p`: named pipe

The next three characters represent the owner's permissions, which can be one or more of the following:

- `r`: read permission

- `w`: write permission

- `x`: execute permission

The next three characters represent the group's permissions, which can be one or more of the following:

- `r`: read permission

- `w`: write permission

- `x`: execute permission

The final three characters represent everyone else's permissions, which can be one or more of the following:

- `r`: read permission

- `w`: write permission

- `x`: execute permission

For example, a permission string of `-rw-r--r--` represents a regular file with read and write permission for the owner, and read-only permission for the group and everyone else.

You can view the permissions of a file or directory by running the `ls -l` command in a terminal. The output will display the permission string, as well as other information about the file or directory, such as ownership and modification time.

What is CHMOD (Change Mode)
`chmod` is a Linux command that is used to change the permissions of files and directories. The name "chmod" is short for "change mode".

In Linux, each file and directory has three sets of permissions: read, write, and execute. These permissions can be set for three different groups of users: the owner of the file or directory, the group that the file or directory belongs to, and everyone else.

The `chmod` command takes a numeric or symbolic mode argument that specifies which permissions to set and for which users. Here's a breakdown of how to use `chmod`:

Numeric mode:

Numeric mode is a way of specifying permissions using a three-digit number. Each digit corresponds to a user group (owner, group, or everyone else), and the digits are calculated by adding up the values of the desired permissions:

- 4 for read permission

- 2 for write permission

- 1 for execute permission

For example, to set read and write permissions for the owner of a file, and read-only permissions for everyone else, you would use the command `chmod 644 filename`, where:

- 6 = 4 (read) + 2 (write) for the owner

- 4 = 4 (read) for the group

- 4 = 4 (read) for everyone else


Symbolic mode:

Symbolic mode is a way of specifying permissions using symbols and operators. Here are the symbols and operators that can be used:

- `u` (user/owner)

- `g` (group)

- `o` (others/everyone else)

- `a` (all users, equivalent to `ugo`)

- `+` (add permission)

- `-` (remove permission)

- `=` (set permission)


For example, to add execute permission for everyone else on a file, you would use the command `chmod o+x filename`.

Here's some additional information about Linux file permissions:

- To change file or directory permissions, you can use the `chmod` command. For example, to give the owner of a file read, write, and execute permission, and remove all permissions for the group and everyone else, you can run:

  $ chmod 700 filename

- You can also use symbolic notation with `chmod`. For example, to give the owner read and write permission, and everyone else only read permission, you can run:


  $ chmod u+rw,o+r filename


  In this notation, `u` stands for "user" (the owner), `g` stands for "group", and `o` stands for "other" (everyone else). The `+` and `-` signs are used to add or remove permissions, and `r`, `w`, and `x` are used to specify read, write, and execute permissions.


- You can change the ownership of a file or directory using the `chown` command. For example, to change the ownership of a file to the user `alice` and the group `users`, you can run:

  $ sudo chown alice:users filename

- You can change the group ownership of a file or directory using the `chgrp` command. For example, to change the group ownership of a file to the group `users`, you can run:

  $ sudo chgrp users filename

- The `umask` command can be used to set default permissions for newly created files and directories. The `umask` value is a 3-digit octal number that specifies which permissions should be masked (i.e. not granted). For example, a `umask` value of `002` would mask the write permission for the group and everyone else. To set the `umask` value, you can add a line like the following to your shell configuration file (`~/.bashrc` or `~/.bash_profile`):

  umask 002

Here are some additional tips and best practices for managing Linux file permissions: