Introduction to Bash Shell Scripting: Linux Commands - Part 2

Owners and Groups

Before we can talk about file permissions, we must look at owners and groups. Each file and directory on your computer has an owner and a group associated to it.

Owner: - usually when you create a file, you become its owner 

Group: - users can join "groups" of other users with whom they can share files and directories
               - A file and directory can only have 
               - Users can "work" in different groups by using the command "newgrp" or  "newgroup"
               - When a user creates a file its group is made to be the group the user was in when the file was created

File Permissions

Every file and directory on your computer has a set of permissions which dictate how an owner, group, or other users can change files. There are three file permissions:

Read (r): 

File: Can be looked at and copied.

Directory: Can look at its contents.

Write (w):

File: Can modify or delete it.

Directory: Add and delete files to/from the directory.

Execute (x):

File: Can execute it, If it is an executable file.

Directory: Weaker than read. Can access a file or directory ONLY if know its name, but can't list contents of directory.

You can view a list of all your files in a detailed view that shows all the files permissions by using the command: 

ls -l

The owner of a file or directory can set the permissions of any give file/directory by using the 'chmod' command. Here is the general format of the command:

chmod (ugoa)(+-=)(rwx) file/directory_name

Starting from left to right, here is the description of each argument in the command after chmod.

(ugoa) - The "user type" you want to change or set permissions for.

u: User/Owner

g: Group

o: Other

a: All


=: Changes to exactly those given permissions
+/-: add, remove given permissions

(rwx) - The permission you want to set

r: Read

w: Write

x: Execute

All of these are then followed by the file or directory name. For example, if you want to change the permissions of a file called 'test', to add execute permission for the owner:

chmod u+x test


- - -   (000)   0
- - x   (001)   1
- w -   (010)   2
- w x   (011)   3
r - -   (100)   4
r - x   (101)   5
r w -   (110)   6
r w x   (111)   7

        chmod 160 test  sets only x for user, only rw for group 
        and no permissions for others

More tutorials coming soon! Let me know how you like the tutorials by commenting below and if there is any specific topics or languages you would like covered.

Programming in C: Increment and Decrement

Programming in C: User Input