Saturday, 13 May 2017

chmod command usage and example

chmod is used to change permissions of files or directories.
The chmod stands for change mode i.e. to change mode of operation of the file.

Syntax
chmod [options] permissions file_name

File ownership
  • Each file is owned by single user.
  • Each file also belongs to a single group.
  • Same ownership principles apply to directories.
Three types of user:
  • User (owner)
  • Group 
  • Other
Three types of protection:
  • Read 
  • Write
  • Execute
Super user can override nine protection flags.

File Permissions
File permissions are rules defined for each file which determines who can access that file, and how it can be accessed.
There are two ways to set these permissions as shown above:
1. Symbols (alphanumeric characters)
2. Octal numbers (0 to 7)

Changing Permissions
Examples
Lets create abc.txt file and see some examples on chmod.
$ touch abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rw-r--r-- 1 32578 32578 0 May 13 09:41 abc.txt   

Granting execute permission to user, group and others.
$ chmod +x abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rwxr-xr-x 1 32578 32578 0 May 13 09:41 abc.txt

Revoking execute permission.
$ chmod -x abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rw-r--r-- 1 32578 32578 0 May 13 09:41 abc.txt


Granting execute permission only to user/owner.
$ chmod u+x abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rwxr--r-- 1 32578 32578 0 May 13 09:41 abc.txt

Granting execute permission only to group members.
$ chmod g+x abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rwxr-xr-- 1 32578 32578 0 May 13 09:41 abc.txt

Granting execute permission only to others.
$ chmod o+x abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rwxr-xr-x 1 32578 32578 0 May 13 09:41 abc.txt

Revoking read permission from user, group and others.
$ chmod -r abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

--w------- 1 32578 32578 0 May 13 09:41 abc.txt

Revoking write permission from user, group and others.
$ chmod -w abc.txt

$ ls -lrt

total 4

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

---------- 1 32578 32578 0 May 13 09:41 abc.txt

Changing permission for user, members of group and others simultaneously.
$ chmod u=rwx,g=rwx,o=x abc.txt

$ ls -lrth

total 4.0K

-rw-r--r-- 1 32578 32578 978 May 13 09:28 add.txt

-rwxrwx--x 1 32578 32578 0 May 13 09:41 abc.txt

Changing permission for user to read, write, execute; members of group to read and execute and others to execute .
$ chmod 755 abc.txt

$ ls -lrth

total 4.0K

-rw-r--r-- 1 32578 32578 978 May 13 09:28 README.txt 
 
-rwxr-xr-x 1 32578 32578 0 May 13 09:41 abc.txt

Friday, 5 May 2017

Database and Database Management System (DBMS)

Database 
A database is any collection of data, it can be words you write on a piece of paper or a digital file. 
It is a collection of interrelated data. 
It is a system intended for storing and retrieving large amount of data. 
DB is made up of tables and contains rows and columns. It is like spreadsheets, excel.


Database Management System (DBMS)
Database Management System (DBMS) is a collection of programs which enables its users to access database, manipulate data, reporting / representation of  data.
Basically it is a piece of software that manages databases and lets you create, edit and delete databases, their tables and their data. 
Examples of a DBMS are MySQL, MS SQL Server, Oracle, PostgreSQL and SQLite.