I have 007 permissions. You know what that means, right?

You need a permit to play with Tux' files: rwx

I have 007 permissions. You know what that means, right?

In the following piece, I've tried to present a succinct but effective description of file-permissions in Linux. Enjoy!


Ijazat

Suppose we are provided with 3 bits, then what values can be stored in it?

rwx

On a UNIX-like system, there are only three things that one can do with a file, namely, read (r), write (w), and execute (x). File-permissions specify whether a file is up for rwx or not. A permission (r, w, or x) is either 0 (NA) or 1 (exists), then the following holds:

The first column in the ls -l command is for file-permissions. It shows what exactly among r, w, and x a particular file is open to, if not all three.

  • For each file, there are ten characters in total. The first one specifies the file-type [d is dir, - is normal file, l is link], followed by "three sets" of rwx, each representing the permissions for a certain owner.

The command

We can use chmod to change the permissions on a file for all the owners in one go. The syntax: chmod <octals> <file>

The following is an illustration for clarity:

  • When it comes to execution, -wx is not a useful permission set, because a file can't be compiled if it can't be read.

  • [The Title] 007 permissions on a file means the user and the group owners are locked out of the file, completely.

Shorthand notation

There's a shorthand for the chmod command that combines letters, operators, and owner references.

  • Letters: r (read), w (write), and x (execute) refer to permissions.

  • Operators: + (add), - (remove), and = (set).

  • Owner ref: u (user), o (others), g (group), and a (all).

Let's consider a script test.sh with permission sets -rw-r--r-- Here's how we can use the shorthand notation:

# add x permission to the user
chmod u+x test.sh
# remove r and w from user
chmod u-rw test.sh
# add x to group and others
chmod go+x test.sh

** The = (equals) character replaces the existing permissions.

** We can use comma (,) to separate different classes when setting permissions.

Consider a file todo.sh with -rw-r--r-- permissions.

# add x to user and rw to group and others
chmod u+x,go=rw todo.sh
# remove all permissions for everyone
chmod a= todo.sh
# user’s permissions to rw, group’s and others’ to r only
chmod u=rw,go=r todo.sh

Thank You😊

Plz like and share✌️