Basic Commands for Ubuntu

This is the continuation of “Very Basic Commands for Ubuntu“. Before reading the following article we suggest you to go through “Very Basic Commands for Ubuntu“. 


1. chmod – change file or directory attributes. If you do “ls -l” in the present working directory, you would see file attributes for your files and directories in the present working directory. To change the permissions you can use “chmod”.

Syntax:

chmod XXX file_name

or

chmod XXX directory_name

Each ‘X’ denotes a value for “user”,”group” and “others” respectively. The ‘X’ above can be assigned value from 0-7. There are three types of permissions having a corresponding ‘X’ value as given below:

 X=4: for read only.

X=2: for write only.

X=1: for execute only.

You can get a combination of permisssions eg. “read and write” by givng ‘X’ a combined value as ‘X=6’ (‘X=6’ is obtained by adding read and write value. Lets assume that you have a file “file.txt” and directory “test”, and you want to assign:

User – read, write and execute permission (X=4+2+1=7);

Group – read and write permissions (X=4+2=6); and

Others – read only permission (X=4).

To do that you can do the following:

chmod 764 file.txt

chmod 764 test

(Here we assume that the file “file.txt” and directory “test” are in present directory).


2. chgrp – To change group attribute of a file or directory. Each user belongs to a group. If you need to change the group  the user belongs to use this command.

Syntax:

chgrp group_name file_name

or

chgrp group_name directory_name

For example, if you have file a file “file.txt” and directory “test”, and you want to assign a group “admin” to it, you can do that by:

chgrp admin file.txt

chgrp admin test

Leave a Reply

Your email address will not be published. Required fields are marked *