Thursday, October 16, 2008

Workshop in Nihiluwa Vidyalaya

Conducted five days workshop in Visual Basic, Mambo (Content Management System) and Microsoft Access for student of Nihiluwa Maha Vidyalaya in 2008 October 16.
 
   

Thursday, August 14, 2008

Linux Commands - Part 5

du - This used to estimate file space usage.

du /home 
{shows usage of /home folder and all other files/folders in home folder}

du -h
/home {show usage in human readable foarmat. Using Mb and Gb}

du –maxdepth=0 /home
{show enrite /home folder usage only, sumerized one}

du –maxdepth=1 /home 
{show enrite /home folder and one level down}

cut - This used to remove sections in each line. This is most of the time used with pipe command

cat /etc/passwd | cut -d":"  -f1
cat /etc/passwd is to show content of the passwd file. We pipe output of that command cut using | (pipe). cut -d":" -f1 {this means split each line of out put by ':' and only display first field (f1)}. Thus if we take only first field we get username. Therefore above command list all the users in our system. 

cat /etc/passwd | cut -d":" -f1-3
{show 1,2,3 field ,example :melick:x:1000}

cat /etc/passwd | cut -d":"  -f1,3
{show 1 and 3 fields ,example :melick:1000}

cat /etc/passwd | cut -c1
{show only first character of each line example :m}

cat /etc/passwd | cut -c1-3
{show 1,2,3 characters of each line example :mel}

cat /etc/passwd | cut -c1,5
{show 1 and 5 characters of each line example :mc}

tr - This command used to translate texts. This is also used with pipe command.

head 5 /etc/passwd | tr '[:upper:]' '[:lower:]'
head 5 /etc/passwd | tr A-Z a-z

head 5 /etc/passwd command will diplay first 5 lines of the passwd file. And we pipe the out put to tr command. And it will translate all text to lower case.

ifconfig - This used to configure a network interfaces. Our network card interface named as eth (Ethernet). Therefore first Ethernet interface is named as eth0. If we have two or more network cards then we have eth1,eth2 as so.. 

ifconfig     {shows only running (up) interfaces details}
ifconfig -a    {show all interfaces details even if down }
ifconfig eth0 192.248.16.100 netmask 255.255.240.0
{this command will add 192.248.16.100 ip address and 255.255240.0 subnet to the eth0 interface}
ifconfig eth0 up           {this will up the interface eth0}
ifconfig eth0 down {this will down the interface eth0}

Thursday, July 24, 2008

Workshop

Done a workshop on a Network Concepts to school guys.
organized by SL Genius

Monday, July 14, 2008

Linux Commands - Part 4

whoami  - This is used get who is the current user.
hostname – This is used to get name of the machine.
who          -Show who is logged into the system.
Date         - Show the current date and time
printenv - Print vales o fall environment variables.
env            -Print current environment.

su -This command is used to change the shell user.

  su -            {change  the shell to the super user / root}
  su - root   {change  the shell to the super user / root}
  su - Saman       {change  the shell to the super Saman}

id - This is used to print user's  information

 id                     {show current user information}
 id Saman         {show user Saman information}

uname - This used to get machine and operating system information

 uname              {show operating system}
 uname -a          {show all info, OS, Kernel version, architecture}
 uname  -r         {show kernel version}

groups  This used to get user belongs group informations

 groups                         { groups of current user}
 groups  Saman             {groups of user Saman}         

 cat  - This is used to show file content

 cat /etc/passwd       {show /etc/passwd file content }

head - This used to show first n lines of a file

 head -10 /etc/passwd  
 {show first 10 lines of the file passwd in /etc }        

tail - This used to show last n lines of a file

 tail -10 /etc/passwd  
 {show last 10 lines of the file passwd in /etc }         

wc - This used to get count {word,line,charactor}

 wc       /etc/passwd 
{show line,word,charactor count of the file passwd}
 wc -l   /etc/passwd 
{show line count of passwd file in /etc folder}
 wc -c   /etc/passwd     
{show characor count of passwd file in /etc folder}
 wc -w   /etc/passwd   
{show word count of passwd file in /etc folder}

ps - This used to get active proccess

  ps                     {show active processes}
  ps aux              {show every all peocesses}

kill - This used to kill (destroy) a process

 kill 1960          {kill a process has id 1960 

Saturday, June 14, 2008

Linux Commands - Part 3

find -This command is use t find files and folders

 find . -name amal -print         
 {find amal in current directory and print output}

 find /home -name a*  -print   
 {find things starts with a in /home directory and print output}

 find /home -name a* -type d  -print   
 {find directories starts with 'a' in /home directory and print output}

 find /home -name a* -type f  -print    
 {find filesstarts with a in /home directory and print output}

 find / -atime +7 -name *.conf -print
 {find every thing end with “.conf” and access before last 7 days in / (root)}

  find / -atime -7 -name *.conf -print
 {find every thing end with “.conf” and access with in last 7 days in / (root)}

  find / -atime 7 -name *.conf -print
  {find every thing end with “.conf” and accessed day 7 / (root)

  find . -name meli -type f -exec rm {} \;
 {find files named 'meli' in current directory and remove them}

  Hints: 
  [-atime,-amin,-ctime,-cmin, -name,-exec, -print, -type]

 locate - This also used to find files

  locate Saman               {find file named Saman}
  locate M*                    {find files start with M}
  locate -c Saman           {display only matching count}

Monday, April 14, 2008

Linux Commands - Part 2

ls - This command is use to list files and folders.

   ls                       {list current directory}
   ls /media         {list /media files and folders in  directory media }
   ls -l                   {list permission}
   ls -a                  {list all, including hidden files, etc}

cp - This command is use to copy files and folders

   cp  test /home/melick { copy test file to /home/melick folder}
   cp  /root/s.txt  .        {copy s.txt to current directory (.)}
   cp -r /root  /home/melick      {copy entire root folder to melick}                 

mv - This is used t move and rename files and folders

  mv  test /home/melick       { move test file to /home/melick folder}
  mv  /root/s.txt  .   { move s.txt file in /root to current folder (.)}
  mv test1 test2         {rename test1 file to test2}          

rm - This is used t delete files and folders

  rm /home/Melick/test      {delete the test file}
  rm -r /home                        {delete the entire home folder}                
 rm -i /home    {ask confirmation to delete}    

mkdir - This is used to create folders.

  mkdir Melick            {create the Melick folder in current directory}
  mkdir /home/Sachika     {create Sachika folder in home directory} 

rmdir  - This is used to delete empty folders

  rmdir Melick            {delete the Melick folder in current directory}
  rmdir /home/Sachika    { delete Sachika folder in home directory}   

ln - This is used to create links (something like shortcuts) 

  ln -s test  shorttest             {create link 'shorttest' to file test }    
  ln -s /home/test  shorttest 
                         {create link 'shorttest' to file test ('home' folder)}
  ln test test2  
 {create hard link 'test2' to file test.create a nother copy of test}              

 Out put of above commands 

lrwxrwxrwx 1 melick melick    4 2008-12-30 00:21 shorttest -> test
  -rw-r--r-- 2 melick melick    0 2008-12-30 00:20 test
  -rw-r--r-- 2 melick melick    0 2008-12-30 00:20 test2

Linux Commands - Part 1

chmod this is the command hat we use to change the permission.

 ex:-

chmod 777  test
{change the permission to 777 the file test in the current directory}
chmod 777 /home/melick/test
{change the permission to 777 the file test in the /home/melick directory}
chmod  g-r test {remove read permission in the group}
chmod  g+r test {add read permission in the group}
chmod  o-r test {remove read permission in the other}
chmod  o+r test {add read permission in the other}
chmod  u-r test {remove read permission in the user/owner}
chmod  u+r test {add read permission in the user/owner}
chmod  u=r test {read permission only to the user/owner}
chmod  u=w test {write permission only to the user/owner}

chownthis command is use to change the owner of the file.

chown root test 
  { if we want to change ownership to the file to the root }
-rw-r--r-- 1 root melick 0 2008-12-21 21:11 test
chown Melick:Sachika test
{change 'test' files owner as Melick and group as Sachika}           

chgrp - this command is use to change the group of the file.

chgrp root test     {change the group to 'root' in the file 'test' } 

Friday, March 14, 2008

Linux Permissions

In linux, file, folder, etc can accesse by three types of user groups.

  1. Owner
  2. Group
  3. Other

and each user group has three types of permissions. read,write, and execute. As an example, (if user has read permision we denote it by using 1 and if not by 0 in binary )

Owner Group Other

rwx    rw-      r--
 111     110     100
 7         6          4

we can use "ls -l" command to view files,folders,links with permissions.

drwxr-xr-x 2 melick melick 4096 2008-11-23 00:32 Music

this is the sample. so we look each and every element further.

drwxr-xr-x

first charactor "d" is for type of the file. there are three types.

  • d = directory (folder)
  • l = link (symbolic link, shortcut)
  • - = file
  • c = charactor device (ex:- /dev/ttys0) {try:- ls -l /dev/ttys0}
  • b = block device (ex:- /dev/sda1)     {try:- ls -l /dev/sda1}
now we consider the permission set in the above folder.

rwxr-xrx- = rwx   r-x        r-x

  owner  group   other
  111       101       101 
 7           5          5   

Thursday, February 14, 2008

About Linux Users

All linx users, their passwords and other details are stored in a one file. It is "passwd" file which is in the "etc" folder. {/etc/passwd}            

If we want to view password file {hm... there are several ways, but for the moment we will use "cat" command}.we will talk about "cat" command later. So in your command prompt {shell,terminal} run below command.

 cat /etc/passwd

This command will give you a file with several rows. One row is for one user. Let have a look on one row.

 melick:x:1000:1000:melickrajee:/home/melick:/bin/bash

 So let see what this line says. Following illustrate the format of the one line           

 username:password:Gid:Uid:Fullname:home folder:shell

 So now we compare those two for further details.

 melick       :x               :1000 :1000  :melickrajee  :/home/melick :/bin/bash

 username :password :Gid    :Uid     :Fullname     :home folder  :shell

  1. melick - Username
  2. x(password) - x is not the password. it says there is a password and its encrypted.
  3. 1000 (Gid) – Group ID
  4. 1000 (Uid) – User ID
  5. melickrajee - (Fullname) 
  6.  /home/melick (home folder) - this line shows what is the default folder for the user                       

/bin/bash (shell) - shell is a command prompt. there are many terminals in the linux like bash,sh,.. so we can define shell is used by the user. /bin/bash mean this user uses the "bash" shell which is in the "bin" folder. 'bash' is a programme also. if we assign the login as /sbin/nologin user cannot log in to the system.