Saturday, March 29, 2014

2:22 AM
3
Good day!

Hello and welcome to another article on my howto; this time we will learn the basics on how permission works and how to use chmod commands effectively on *nix.

This is the third part of my howto in "Learning Linux/UNIX"


File permissions:

file permission

The -rw-rw-r-- is read in triples of 3. This tells the user what the file permissions are.

-    is an ordinary file
d   is a directory
b   is a block file
c   is a character file
And a set of permissions called as mode:

r    stands for read permission
w   is write permission
x    is execute permission

Also, Linux and almost all other UNIX systems have three user classes as follows:

User (u): The owner of file
Group (g): Other user who are in group (to access files)
Other (o): Everyone else

The first column is read in 3 triples as stated above. The first group of 3 (in -rw-rw-r--) after the "-" specifies the permission for the owner of the file, the second triple are for the groups (the fourth column) and the last triple are the permissions for all other users.

Therefore if for example I have a set of permission like this -rwxr-x--- is read as follows..

The owner index- has permission to read, write and execute anything in the directory but the groups has no write permission to it and the rest of the users have no permission at all. The format of one of the lines in the above output is as follows:

file type-permissions, links, owner, owners group, bytes taken, date, time when last accessed, directory or file name.


chmod

change file mode bits. The chmod command changes permission of a directory or a file. To setup file permission you need to use chmod command:

chmod [mode] [filename]

ex:
chmod who+, -,=r,w,x

The who is substituted by u-user, g-group, o-other users, a-all. The + means add permission, - means remove permission, = - assign.

To setup a file that you wanted all other users to read the file name todo.txt, type:

$ chmod o+r todo.txt

You can also change permissions for all files and directories within a directory by using the -R option on the chmod command.

3 comments:

  1. for more details use this command
    chmod --help

    ReplyDelete
  2. Thanks for the additional info.
    read = 4
    write = 2
    execute = 1

    Is the octal representation for the file permissions. It is quite useful for advance *nix user for remembering the meaning of write, read, and execute.

    For ex. you can create a triplet rwx like this
    r w x
    4+2+1=7

    0 means remove permission, so for example if you want to give full permission to the user you can do:

    $ chmod 0700 todo.txt

    ReplyDelete