Linux File Permissions :
In Linux every thing is a file, so to be able to understand Linux we should have an idea how to work with files.

To check the permission of a file we can use ls -all command that will list down all the files and directory with file permissions, file size, last time acessed and name of file/directory.

#To check permission of files we use ls -all
$ls -all
total 697288
drwxr-xr-x+ 26 rahul  staff   884B Oct  4 19:26 .
drwxr-xr-x   6 root   admin   204B Jun  8 19:30 ..
drwxr-xr-x+  5 rahul  staff   170B Jun  8 19:26 Public
drwx------+  3 rahul  staff   102B Jun  8 19:26 Movies
drwxr-xr-x   4 rahul  staff   136B Jun 10 12:29 .composer
-rw-------   1 rahul  staff   8.6K Jul  2 22:35 .viminfo
drwx------   3 rahul  staff   102B Jun  9 08:01 .ssh
drwx------+  4 rahul  staff   136B Jun  9 20:47 Music
-rw-r--r--   1 rahul  rahul   212B Jun  3 08:12 crontab
lrwxrwxrwx   1 rahul  rahul   212B Jun  4 09:32 public_html -> l5/pub/

                            
Permission Details :
This section will explain the series of letters and dashes that define the file permissions.

The first character in list indicates the type of file.
In the above example, the first character in each list was either a dash (-) or letter d.
  • A dash - indicates that the file is a regular file.
  • The letter d indicates that the file is a directory, which is basically a special kind of file.
  • A special file type that you see in last is called a soft link. It begins with a lowercase l. A soft link is a pointer to another location in the file system.

Permission abbreviations :
Permissions for files are represented by the following letters.
  • r refers to the read permission for file or directory.
  • w refers to the write permission for file or directory.
  • x refers to the execute/search permission for file/directory.

Permission Characters :
  • The first trio of letters after the file type in a file list rwx represents permission for the file owner.
  • The next trio of characters rwx represents permission for the group category.
  • The last trio of characters rwx represents permission for the final category i.e. others.

Modifying access permissions :
Permission of file can be represented in octal notation.
In octal notation,
  • Read or r is represented by 4.
  • Write or w is represented by 2.
  • Execute x is represented by 1.

Sum of these three is use to represent the permission. So, to change the access permissions for a file or directory use the command chmod.

Each row in below table has 2 examples, one for setting that permission for a file, and one for a directory named dirname.

Permission Command Examples Description
rwx rwx rwx chmod 777 filename
chmod -R 777 dirname
Anybody can read, write, execute.
rwx rwx r-x chmod 775 filename
chmod -R 775 dirname
Owner & Group can read, write, execute. Everyone else can read, execute.
rwx rwx r-- chmod 774 filename
chmod -R 774 dirname
Owner & Group can read, write, execute. Everyone else can read.
rwx r-x r-x chmod 755 filename
chmod -R 755 dirname
Owner can read, write, execute. Everyone else can read, execute.
rwx --- --- chmod 700 filename
chmod -R 700 dirname
Owner can read, write, execute. No one else has any rights.
rw- rw- rw- chmod 666 filename
chmod -R 666 dirname
Everyone can read, write.
rw- rw- r-- chmod 664 filename
chmod -R 664 dirname
Owner & Group can read, write. Everyone else can read.
rw- r-- r-- chmod 644 filename
chmod -R 644 dirname
Owner can read, write. Everyone else can read.
About Me
Rahul Yadav

Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.

I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding and technology learning experiences.

In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.

Tag Cloud