FurtherTopics/Command Line File Permissions

From HPC
Revision as of 09:50, 16 November 2022 by Pysdlb (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation , search

Back to Command Line Quickstart

Back to Further Topics

File Permissions in Linux

Similar to many other operating systems Linux uses a method of access rights on files and directories. These can be viewed by using the ls command


username@viper:~$ ls –l   (option l is for long listing)

-rw-r--r--  1 dbird admin    12211 May 11  2016 template.countries
-rw-r--r--  1 dbird admin     3097 May 11  2016 template.languages    (1)
drwxr-x---  2 dbird admin     4096 Dec  1 10:54 Templates       (2)
-rw-r--r--  1 dbird admin     8087 Feb 12 14:05 temp.txt
-rwx------  1 dbird admin     1110 Mar  8 10:53 test4pisignage.pl    (3)

Each file and directory has access rights that are associated with each one. When we look at the 10 symbol string above on the left-hand side (e.g. drwxr-xr-x).

  • The first letter presents whether the file is a directory or not.
  • The next three represent the file permission for the user that owns that file (i.e. dbird in this example).
  • The next three represent the file permission of the group to whom that user belongs (i.e. group admin).
  • The last three represent the file permissions for everyone else (i.e. all users).

For each of the permission parts the letters mean the following in their groups:

  • r indicates read permission to read and copy the file, its absence indicates this is not available.
  • w indicates write permission to write the file, its absence indicates this is not available.
  • x indicates execution permission to allow the file to be executed, its absence indicates this is not available.


Using the example above would mean:

  • Example (1) has read/write access for user dbird and read access only for everyone else.
  • Example (2) is a directory with full access for user dbird and read access for only users in the admin group.
  • Example (3) is an application which is only accessible by the user dbird, note not only is it read and write but it also has its ‘execution’ permission set for that user also.


Changing access rights

This command allows the user to change file (and directory) permissions.

  • u User
  • g Group
  • o Other
  • a All
  • r Read
  • w Write (and erase)
  • x Execution (and access directory
  • + Add permission
  • - Remove permission



username@viper:~$ chmod go-rwx myfile.c   (remove read, write and execute permissions removed for group and others)
username@viper:~$ chmod u+x myapp.pl   (make the program myapp.pl executable to the user (i.e. the owner of the file))



Back to Further Topics / Back to Command Line Quickstart / Main Page