• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
OpenGurukul : Operating System : Linux

OpenGurukul : Operating System : Linux



Linux By OpenGurukul

Linux By OpenGurukul



Total Views
Views on SlideShare
Embed Views



1 Embed 147

http://www.opengurukul.com 147


Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    OpenGurukul : Operating System : Linux OpenGurukul : Operating System : Linux Presentation Transcript

    • LINUX By OpenGurukul.comFree/Open Source Software Laboratory
    • LINUXModule : History www.opengurukul.com 2
    • Unix : HistoryUNIX Variants IBM AIX Oracle/Sun Solaris HP HP-UX www.opengurukul.com 3
    • Unix : HistoryLINUX (Unix like operating system) Distributions Redhat Fedora (Free Edition), RHEL (Redhat Enterprise Linux) Novell SLED(Suse Linux Enterprise Desktop), SLES (Suse Linux Enterprise Server) Canonical Ubuntu (derived from Debian) Oracle Enterprise Linux (derived from RHEL) CentOS (derived from RHEL) www.opengurukul.com 4
    • LINUXModule : File Systems www.opengurukul.com 5
    • Linux : File SystemsComputers store information in things called files.A file is like a sheet of paper with something writ-ten on it.Files are stored in things called directories (popu-larly known as folders on windows). www.opengurukul.com 6
    • Linux : File Systems : pwdpwd : print name of current/working directoryUsage:$ pwdExample:$ pwd/home/sachin$ echo $HOME/home/sachin www.opengurukul.com 7$
    • Linux : File Systems : cdcd : change directoryUsed to change current working directoryUsage:$ cd <dirname>Example:$ cd /tmp$ pwd/tmp$ www.opengurukul.com 8
    • Linux : File Systems : cd to home directorycd ~ : cd to home directory cd : cd without arguments to go to home directoryExample : Example :$ cd ~ ; pwd $ cd ; pwd/home/sachin /home/sachin$ $ www.opengurukul.com 9
    • Linux : File Systems : cdcd .. : cd to parent directory cd - : cd to previous working directoryExample : Example:$ cd ~ ; pwd $ cd /z/y/x/w/v/u; pwd/home/sachin /z/y/x/w/v/u$ cd .. ; pwd $ cd /a/b/c/d/e/f; pwd/home /a/b/c/d/e/f$ $ cd -; pwd /z/y/x/w/v/u www.opengurukul.com 10 $
    • Linux : File Systems : mkdirmkdir : make directories Example : $ cd $HOMEOptions : $ mkdir lab-p : no error if it already $ mkdir lab exists, make parent mkdir: cannot create directory directories as needed `lab: File exists $ mkdir -p labUsage : $ mkdir -p lab/scratch$mkdir <dirname> www.opengurukul.com 11
    • Linux : File Systems : catcat – concatenate files and print on the standard outputUsage:$ cat <list of files>Example:$ cat /etc/issueFedora release 14 (Laughlin)Kernel r on an m (l)$ www.opengurukul.com 12
    • Linux : File Systems : headhead – output the first part of filesThe head command without any argument displays first 10 lines ofa file.Usage:$ head <filename>Example: To display first two lines$ head -2 /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin$ www.opengurukul.com 13
    • Linux : File Systems : tailtail – output the last part of filesThe tail command without any argument displays last 10 lines of afile.Usage:$ tail <filename>Example: To display last two lines$ tail -2 /etc/passwdoracle:x:501:501::/usr/lib/oracle/xe:/bin/bashtomcat:x:91:91:Apache Tomcat:/usr/share/tomcat6:/sbin/nologin$ www.opengurukul.com 14
    • Linux : File Systems : moremore : paging through text one screenful at a time.The command also shows % of text already covered at bottom.Usage:$ more <filename>Commands:To quit – press qTo go to next page – press space barTo go to prev page for files (not for pipes) – press bExample:$ more /etc/httpd/conf/httpd.conf www.opengurukul.com 15$
    • Linux : File Systems : lessless : similar to more.Less allows backward movement in the file as well as forwardmovementUsage:$ less <filename>Commands:To quit – press qTo go to prev/next page – press page up/downExample:$ less /etc/httpd/conf/httpd.conf www.opengurukul.com 16$
    • Linux : File Systems : touchtouch – create a zero size file / change time stampCreates a zero size file if the file doesnt exist.Change modification time if the file already exists.Usage:$ touch <filename>Example:$ cd ~/lab/scratch$ touch touch.txt$ cat touch.txt$ www.opengurukul.com 17
    • Linux : File Systems : echoecho – display text to standard outputUsage:$ echo <text>Example:$ cd ~/lab/scratch$ echo “Hello World”Hello World$ www.opengurukul.com 18
    • Linux : File Systems : lsls - list directory contentsOptions:-a show entries starting with dot (.) and dot dot (..)-l show long listing format-t sort by modification time-r reverse the orderExample:$ cd /home$ lssachin surikuma root ksurinde laxmi yukta kumasuri sunil saurav$ www.opengurukul.com 19
    • Linux : File Systems : ls -als -a : do not ignore entries starting with dotExample :$ cd ~/lab/scratch$ touch .system.txt$ lsecho.txt touch.txt$ ls -a.system.txt echo.txt touch.txt$ www.opengurukul.com 20
    • Linux : File Systems : ls -lls -l : use a long listing format<file type> <permissions> <link count> <file owner> <group ofowner> <file size> <date of modification> <time of modification><file name>Example :$ cd /bin$ ls -l *sh*-rwxr-xr-x. 1 root root 877480 Jun 22 2010 bash-rwxr-xr-x. 1 root root 102408 Jun 21 2010 dashlrwxrwxrwx. 1 root root 4 Jan 27 2011 sh -> bash-rwxr-xr-x 1 root root 597768 Mar 22 2010 zsh www.opengurukul.com 21$
    • Linux : File Systems : ls -tls -t : sort by modification timeExample :$ cd /bin$ ls -lt *sh*lrwxrwxrwx. 1 root root 4 Jan 27 2011 sh -> bash-rwxr-xr-x. 1 root root 877480 Jun 22 2010 bash-rwxr-xr-x. 1 root root 102408 Jun 21 2010 dash-rwxr-xr-x 1 root root 597768 Mar 22 2010 zsh$ www.opengurukul.com 22
    • Linux : File Systems : ls -rls -r : reverse order while sortingExample :$ cd /bin$ ls -ltr *sh*-rwxr-xr-x 1 root root 597768 Mar 22 2010 zsh-rwxr-xr-x. 1 root root 102408 Jun 21 2010 dash-rwxr-xr-x. 1 root root 877480 Jun 22 2010 bashlrwxrwxrwx. 1 root root 4 Jan 27 2011 sh -> bash$ www.opengurukul.com 23
    • Linux : File Systems : lnln : create hard/soft links between filesSoft Link (Symbolic Link): The symbolic link contain path of the target link. The symbolic link can cross boundaries of file systems.Hard Link: Hard links are supported within a file system and these are used to refer to an existing content by some other name within the same file system. The inode number will be same for hard links. Most of the file systems do not support hard linking directories. www.opengurukul.com 24
    • Linux : File Systems : ln & ln -sUsage: Example :$ ln -s <old path> <new_name> Symbolic Link (ln -s):-s : create a symbolic link $ cd /binwithout -s : creates a hard link $ ln -s bash sh $NOTE :On AIX, /bin/sh is a hard linked Hard Link (ln):to /bin/ksh. $ cd /binOn Linux, /bin/sh is a soft link $ ln ksh shto /bin/bash. $ www.opengurukul.com 25
    • Linux : File Systems : soft linkExample :$ ls -l /bin | grep -e ^l | grep -e vilrwxrwxrwx. 1 root root 2 Jan 27 2011 ex -> vilrwxrwxrwx. 1 root root 2 Jan 27 2011 rvi -> vilrwxrwxrwx. 1 root root 2 Jan 27 2011 rview -> vilrwxrwxrwx. 1 root root 2 Jan 27 2011 view -> vi$ www.opengurukul.com 26
    • Linux : File Systems : cpcp: copy files and directoriesSYNOPSIS :cp SOURCE DESTcp SOURCE... DIRECTORYCopy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORYOption :-R copy directories recursively (otherwise directories will be omitted) www.opengurukul.com 27
    • Linux : File Systems : cpcp: copy files and directoriesExample :$ cp ~/.bashrc ~/.bashrc.orig$ cp /etc/profile.d ~/cp: omitting directory `/etc/profile.d$ cp -R /etc/profile.d ~/$ www.opengurukul.com 28
    • Linux : File Systems : mvmv: move (rename) filesSYNOPSIS :mv [OPTION]... SOURCE DESTmv [OPTION]... SOURCE... DIRECTORYDESCRIPTIONRename SOURCE to DEST, or move SOURCE(s) to DIRECTORYExample:$ cp ~/.bashrc /tmp$ mv /tmp/.bashrc /tmp/.bashrc.new$ ls /tmp/.bashrc*/tmp/.bashrc.new www.opengurukul.com 29$
    • Linux : File Systems : rmrm : remove files or directoriesSYNOPSIS:rm [OPTION]... FILE...Options:-i : interactive (prompt before every removal)-f : ignore nonexistent files, never prompt (force)-r : remove directories and their contents recursively www.opengurukul.com 30
    • Linux : File Systems : rm exampleExample (rm) :$ cd /tmp$ touch rm1.out$ rm rm1.out$ ls rm1.outls: cannot access rm1.out: No such file or directory$ www.opengurukul.com 31
    • Linux : File Systems : rm -iExample (rm -i) :$ cd /tmp$ touch rm2.out$ rm -i rm2.outrm: remove regular file rm2.out? Y$ ls rm2.outls: cannot access rm2.out: No such file or directory$ www.opengurukul.com 32
    • Linux : File Systems : rm -fExample (rm -f) :$ rm non_existent_file.txtrm: cannot remove `non_existent_file.txt: No such file or directory$ rm -f non_existent_file.txt$ www.opengurukul.com 33
    • Linux : File Systems : rm -rExample (rm -r) :$ cd /tmp$ mkdir scratch$ rm scratchrm: cannot remove `scratch/: Is a directory$ rm -rf scratch$ www.opengurukul.com 34
    • LINUXMODULE : VI – Text Editor www.opengurukul.com 35
    • LINUX: VI EditorTo invoke Type vi or vi filename.To come out of vi editor Use ESC (get into command mode), followed by : (ex editor mode), followed by q (quit) and then press ENTER.$ vi Hi I am Open Gurukul:q$ www.opengurukul.com 36
    • LINUX: VI Editor : ModeThe VI editor run in 3 different modes INSERT mode COMMAND mode ED/EX Editor mode www.opengurukul.com 37
    • LINUX: VI Editor : Command ModeCommand mode Use ESC to go to COMMAND mode anytime. The typed character will not be visible in COMMAND mode. Under COMMAND mode, each character has special significance and the designated action takes place. www.opengurukul.com 38
    • LINUX: VI Editor : INSERT ModeINSERT mode The characters typed are visible when the editor is in INSERT mode.To get into INSERT mode from command mode i – insert shift+a – insert at end of line www.opengurukul.com 39
    • LINUX: VI Editor : EX ModeED/EX Editor mode The ED/EX editor commands are typed after typing : in command mode. From INSERT mode, we can use ESC + : to get into ED/EX mode. www.opengurukul.com 40
    • LINUX: VI Editor : CommandsINSERT i – insert shift+a – append at end of lineDELETE x – delete a single character dw – delete a word dd – delete a line www.opengurukul.com 41
    • LINUX: VI Editor : CommandsUndo / Redo u – undo the last commands action . (dot) – redo the last commands actionRepeat Action <repeat_count>command 5dd – deletes 5 lines www.opengurukul.com 42
    • LINUX: VI Editor : Cursor MovementCursor Movement Commands /| h – move left on the current line | j – move down one line | k – move up one line<-- -- -- h j k l -- -- --> l - move right on the current line | | !/ www.opengurukul.com 43
    • LINUX: VI Editor :Ex :Save & Quit:w write contents to a file:w /tmp/1.out write contents to file /tmp/1.out:q quit (will not work if there were changes after last write):wq write and quit:q! quit (ignore recent modifications) www.opengurukul.com 44
    • LINUX: VI Editor : Copy & Pasteyy – yank line into buffer <number_of_lines>yy – yank multiples lines into buffer (2yy – yank 2 lines into buffer)Go to line where the content of buffer has to be pasted. Type p to print contents of buffer www.opengurukul.com 45
    • LINUX: VI Editor: Search Pattern/pattern To goto a line that matches pattern.?pattern To go to a line that matches pattern in the reverse direction.n Go to next such pattern match.N (shift+n) Go to next such pattern match in reverse direction.:set ic www.opengurukul.com 46 To ignore case while searching, set ic.
    • LINUX: VI Editor: Line NumbersDisplay Line Numbers :set nu # To display line numbersDo not Display Line Numbers :set nonu # To stop displaying line numbersTo goto a particular line :1 # first line in the file :$ # last line in the file :line_num # Goto line number line_num www.opengurukul.com 47
    • LINUX: VI Editor: Search & ReplaceTo replace old pattern with the new pattern in entire file. :1,$s/old/new/g replace old with new in entire file from first line to last line. :.,+50s/old/new/g replace old with new in file from current line (.) to next 50 lines www.opengurukul.com 48
    • LINUX: VI Editor: Editor OptionsTo see options that are currently set. :setTo see all the options :set all www.opengurukul.com 49
    • LINUX: VI Editor: Multiple FilesTo operate on multiple files, specify all of them while invoking vi editor.$ vi /tmp/1.txt /tmp/2.txt:files # to see files opened by vi editor:n # to go to next files:rew # to rewind to the first file$ www.opengurukul.com 50
    • LINUXModule : Environment www.opengurukul.com 51
    • Linux : Environment : printenvprintenv : print all or part of environmentUsage:printenvExample:$ printenv | grep -e HOME -e PWD -e SHELL -e USER -e HOSTNAMEHOSTNAME=sachin-pcSHELL=/bin/bashOLDPWD=/tmpUSER=sachinPWD=/home/sachin/lab/linux/scratchHOME=/home/sachin$ www.opengurukul.com 52
    • Linux : Environment : exportexport: exports an environment variableTo set an environment variable so that it is visible to even childprocesses.Example :$ export MY_NAME=sachin1$ echo $MY_NAMETo set an environment variable$ MY_NAME=sachin1 (It will not be visible to child processes.)$ echo $MY_NAME www.opengurukul.com 53
    • LINUX : Environment : PS1PS1 : stores value of primary promptExample :$ export PS1=c: > # change the promptc: > export PS1=$ # revert the prompt$ www.opengurukul.com 54
    • LINUX : Environment : PS2PS2Stores value of secondary prompt.Used when the command line is incomplete.Default secondary prompt is >.Example :$ echo hello>$ www.opengurukul.com 55
    • Linux : Environment: HOME and PATHHOME : stores home directory of user.$ echo $HOME/home/sachin$PATH : stores list of directories that should be searched for the executable if the absolute/relative path of an executable has not been specified.$ echo $PATH/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin$ www.opengurukul.com 56
    • Linux : Environment: PWD & OLDPWDPWD : has value of current working directory.$ cd /tmp$ echo $PWD/tmp$OLDPWD : has value of last working directory$ cd /var; cd /tmp$ echo $OLDPWD/var$NOTE :The value of OLDPWD is used by command “cd -” to go back to last working www.opengurukul.com 57 directory
    • Linux : Environment: SHELL, HOSTNAME, USERSHELL : To know path of SHELL program.$ echo $SHELL/bin/bash$HOSTNAME : To know host name$ echo $HOSTNAMEsachin-pc$USER : Name of User logged in.$ echo $USERsachin www.opengurukul.com 58$
    • Linux: Environment: BASH Files/etc/profile : system wide initialization fileIt is executed for login shells.$HOME/.bash_profile : personal initialization fileIt is executed for login shells.$HOME/.bash_logout : individual login shell cleanup fileIt is executed when a login shell exits.$HOME/.bash_history : command history list fileIt stores commands executed by us. www.opengurukul.com 59
    • Linux: Environment: Historyhistory : display the command history list with line numbersThe history command displays the command history list with line numbers.$ history1037 cd /var; cd /tmp;1038 echo $OLDPWD$Execute a command from history :$ !1037 # to execute 1037th command.HISTSIZE : number of commands to be stored in history file$ echo $HISTSIZE1000$ www.opengurukul.com 60
    • LinuxModule : FILE ACCESS www.opengurukul.com 61
    • Linux: File Access: whoamiwhoami : print effective user id$ whoamisachin$groups : print the groups a user is in$ groupssachin$ www.opengurukul.com 62
    • Linux: File Access: id & chmodid : print user identity$ iduid=500(surikuma) gid=500(surikuma) groups=500(surikuma)$chmod : change file mod bits www.opengurukul.com 63
    • Linux: File Access: file type<filetype> <rwx perm for owner> <rwx perm for group> <rwx perm for others>Regular file : -Directory : dPipes : pCharacter device special files : cBlock device special files : bFor symbolic links : lFor sockets : s www.opengurukul.com 64
    • Linux: File Access: chmodUser / Group / Other Read / Write / Execute r(read)u (user) w(write)g (group) x(execute)o (other) Octal Numbers for R / W / X 4 – read 2 – write 1 - execute (file) / search (directory) www.opengurukul.com 65
    • Linux: File Access: chmodPermissions Calculations Octal NumberRWX 4+2+1 7RW- 4+2 6R-X 4+1 5R-- 4 4-WX 2+1 3-W- 2 2--X 1 1 www.opengurukul.com 66
    • Linux: File Access: chmodTo give all the permissions to everybody on a file/directory$ chmod 777 path$To give execute permission on a file$ chmod +x path$To give execute permission on a file to user alone$ chmod u+x path www.opengurukul.com 67$
    • Linux: File Access: umaskumask : unix mask$ umask022$Initial permission fornew file : 666 - umasknew directory : 777 - umaskNOTE :On Linux, umask is 002 in case user name and groupname are same. www.opengurukul.com 68
    • Linux: File Access: chownchown : change file owner & groupThe -R option is used to change the ownershiprecursively.$ chown -R <username>:<group name> <path> www.opengurukul.com 69
    • Linux MODULE :Filters (wc, grep, sed, awk, sort) www.opengurukul.com 70
    • Linux: Filters: wcwc : print newline, word, and byte counts for each file$ wc /etc/passwd 56 98 2916 /etc/passwd$wc -l : print the newline counts$ wc -l /etc/passwd56 /etc/passwd$NOTE:The wc stands for wordcount. www.opengurukul.com 71
    • Linux: Filters : wcwc -w : print the word counts$ wc -w /etc/passwd98 /etc/passwd$wc -c : print the byte counts$ wc -c /etc/passwd2916 /etc/passwd$ www.opengurukul.com 72
    • Linux: Filters: grepgrep : print lines matching a patternSyntax :grep [OPTIONS] PATTERN [FILE...]Example :$ grep root /etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin$ www.opengurukul.com 73
    • Linux: Filters: grep -e & -Egrep -e PATTERN : use PATTERN for search$ grep -e sync -e shutdown /etc/passwdsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown$grep -E PATTERN : egrep - use extended PATTERN for search$ grep -E sync|halt /etc/passwdsync:x:5:0:sync:/sbin:/bin/synchalt:x:7:0:halt:/sbin:/sbin/halt www.opengurukul.com 74$
    • Linux: Filters: grep -fgrep -f file : patterns are kept in file$ cat /tmp/patterns.txtsynchalt$ grep -f /tmp/patterns.txt /etc/passwdsync:x:5:0:sync:/sbin:/bin/synchalt:x:7:0:halt:/sbin:/sbin/halt$ www.opengurukul.com 75
    • Linux: Filters: grep -vgrep -v : Invert the sense of matching, to select non- matching lines$ cat /etc/passwd | grep -v nologin | grep -v bashsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltjetty:x:490:481::/usr/share/jetty:/bin/sh$ www.opengurukul.com 76
    • Linux: Filters: grep -ngrep -n : Prefix each line of output with the line number within its input file$ grep -n -e halt -e sync -e shutdown /etc/passwd6:sync:x:5:0:sync:/sbin:/bin/sync7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown8:halt:x:7:0:halt:/sbin:/sbin/halt$ www.opengurukul.com 77
    • Linux: Filters: grep -igrep -i : Ignore case distinctions in both the PATTERN and the input files$ grep ROOT /etc/passwd$ grep -i ROOT /etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin$ www.opengurukul.com 78
    • Linux: Filters: sortsort : sort lines of text Example :files $ sort lamp.txt$ cat lamp.txt lang: php, perl, pythonos: linux os: linuxwebserver: apache rdbms: mysqlrdbms: mysql webserver: apachelang: php, perl, python $$ www.opengurukul.com 79
    • Linux: Filters: sort -nsort -n : compare $ sort sort.txt according to string 10 numerical value 2 $$ cat sort.txt $ sort -n sort.txt 22 10 $10$ www.opengurukul.com 80
    • Linux: Filters: sort -usort -u : unique records $ sort sort_u.txtThe uniq command also helloselect unique adjacent lines. helloThe uniq command is alsodependent on sort command HELLOto sort the records. HELLO$ cat hello.txt $HELLOhello $ sort -u sort_u.txtHELLO hellohello HELLO$ $ www.opengurukul.com 81
    • Linux: Filters: sort -rsort -r : reverse the result Example : of comparisons $ sort -r lamp.txt$ cat lamp.txt webserver: apacheos: linux rdbms: mysqlwebserver: apache os: linuxrdbms: mysql lang: php, perl, pythonlang: php, perl, python $$ www.opengurukul.com 82
    • Linux: Filters: sedsed – stream editorused for search and replace operation on a file.Syntax :sed -e s/old pattern/new word/gi file/g is to replace globally. Multiple patterns on the same line will be replaced./i is to ignore care while matching pattern www.opengurukul.com 83
    • Linux: Filters: sed -eExample: Example:$ sed -e s/mysql/oracle/gi $ sed -e s/mysql/oracle/gi lamp.txt -e s/php/perl/gi lamp.txtos: linux os: linuxlang: php, perl, python lang: perl, perl, pythonrdbms: oracle rdbms: oraclewebserver: apache webserver: apache$ $ www.opengurukul.com 84
    • Linux: Filters: awkawk - pattern scanning and AWK Variables : processing language $0 – current recordawk is mainly used for $1 – first field of current selecting fields from the record output. $2 – second field of currentSyntax : recordawk -Ffs /pattern/ {action} ...Option : $NF – last field of C.R.-F is used to specify field NF – number of fields in C. separator (default is white R. space) NR – number of records read www.opengurukul.com 85 so far
    • Linux: Filters: awk exampleExample :To display first and last entry for root user.$ awk -F: /^root/ { printf("%s %sn",$1, $NF); } /etc/passwdroot /bin/bash$ www.opengurukul.com 86
    • LinuxMODULE : PROCESS www.opengurukul.com 87
    • Linux: Process: psps : report a snapshot of the current processesIt displays PID(process id), TTY(terminal), and CMD(command) ofexisting processes.Example :$ psPID TTY TIME CMD17286 pts/0 00:00:00 bash$ www.opengurukul.com 88
    • Linux: Process: ps -eps -e : to see all the processesExample :$ ps -e | head -3 PID TTY TIME CMD 1? 00:00:01 init 2? 00:00:00 kthreadd$NOTE : www.opengurukul.com 89-e is equivalent to -A.
    • Linux: Process: ps -fps -f : does full-format listingIt can be combined with any other option.It displays uid (user id), pid (process id), ppid (parent process id), c (nice value), stime (start time), tty, time executed and cmd.Example:$ ps -ef | head -2UID PID PPID C STIME TTY TIME CMDroot 1 0 0 09:12 ? 00:00:01 /sbin/init$ www.opengurukul.com 90
    • Linux: Process: jobsjobs : List active jobsIf a programs takes more time during execution, it can be put into background by using & at the end in the command line.The process which is either running in the background or is in the stopped state is shown in the jobs.Example:$ sleep 60 &[1] 12721$ jobs[1]+ Running sleep 60 &$ www.opengurukul.com 91
    • Linux: process: fg & bgfg : run job in the foregroundTo bring the process from background to foreground (terminal), use fg command.Example:$ fg %job_numberbg : run job in the backgroundTo run a suspended job in the background use bg command.Example:$ bg %job_number www.opengurukul.com 92
    • Linux: process: ^Z & killCONTROL+Z : to suspend a kill : send a signal to job processTo stop a foreground process, Example: use CONTROL+Z. $ kill %job_numberExample:$ sleep 60 NOTE:^Z It will send SIGTERM(15) to job[1]+ Stopped sleep 60 number.$ jobs[1]+ Stopped sleep 60$ www.opengurukul.com 93
    • Linux: Process: jobs example$ sleep 60 & $ jobs[1] 12721 [1]+ Stopped sleep 60$ jobs $ bg %1[1]+ Running sleep 60 & [1]+ sleep 60 &$ fg %1 $ jobssleep 60 [1]+ Running sleep 60 &^Z $ kill %1[1]+ Stopped sleep 60 [1]+ Terminated sleep 60$ $ jobs $ www.opengurukul.com 94
    • Linux: process: killkill: signal a processTo send a signal to a process, kill command is used.Example :$ kill -<signal_number> <PID>The signal number 9 is for SIGKILL.$ kill -9 $$ # will send SIGKILL(9) to your shell program$ kill <pid> # will send SIGTERM (15) to the pid.$ kill -l # to see list of signalsNOTE :Signal SIGKILL cannot be masked. Used to kill the process. www.opengurukul.com 95
    • Linux : processes: nohupnohup : run a command immune to hangups, with output to a non-ttySyntax:nohup commandNOTE:Sends the output to nohup.out or $HOME/nohup.out. www.opengurukul.com 97
    • LinuxMODULE : DISK www.opengurukul.com 98
    • Linux: disk: fdiskfdisk: Create & Edit Partition Table.Example:To print partition table$ fdisk /dev/sdaCommand (m for help): pDisk /dev/sda: 120.0 GB, 120034123776 bytes255 heads, 63 sectors/track, 14593 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x3db20996Device Boot Start End Blocks Id System/dev/sda1 * 1 25 200781 83 Linux/dev/sda2 26 14593 117017460 8e Linux LVMCommand (m for help): q www.opengurukul.com 99
    • Linux: disk : mkfsmkfs : build a file systemTo create file system on partition (logical volume)Example:$ mkfs /dev/hda2$/etc/fstab : file system tableThe file system table that maps partitions to be mounted and the directory on which it has to be mounted.Example:$ cat /etc/fstab# partition mount-directory fs-type mount-options dump fsck-order/dev/sda1 / ext4 defaults 1 1 www.opengurukul.com 100$
    • Linux: disk : mount & unmountmount : mount a file systemMount file systems on partitions (logical volumes) to directories.Example:$ mount /dev/cdrom /mnt/cdimage$umount : unmount a file systemUnmount a file system from directoryExample:$ umount <mounted dir name> # dirname on which fs has been mounted.$ umount /dev/cdrom # or umount /mnt/cdimage www.opengurukul.com 101
    • Linux: disk : dudu : estimate file space usageTo check disk used @ directory level.Options :-s summary (do not display for each directory)-h print sizes in human readable format (e.g., 1K 234M 2G) www.opengurukul.com 102
    • Linux: disk : du example$ du -sh /etc/rc.d596K /etc/rc.d$ www.opengurukul.com 103
    • Linux: disk : dfdf : report file system disk space usageTo check free space on a partition (logical volume)Options :-h in human readable formatUsage :$ df # see all mounted file systemsor$ df <mounted directory name> www.opengurukul.com 104
    • Linux: disk : df example$ df -hFilesystem Size Used Available Use% Mounted on/dev/mapper/VolGroup00-rootlv 77G 23G 51G 31% //dev/sda1 190M 47M 134M 26% /boot/dev/mapper/VolGroup00-datalv 29G 22G 6.1G 78% /data$$ df -h /homeFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-rootlv 77G 23G 51G 31% /$ www.opengurukul.com 105
    • LINUXMODULE : NETWORK www.opengurukul.com 106
    • Linux: Network: ifconfigifconfig : configures a network interfaceUsed to configure a network interface.Also used to retrieve configuration of network interface like ip address of the Ethernet network interface eth0.Option:-a show all interfacesExample:To know ip address of Ethernet network interface eth0.$ /sbin/ifconfig -aeth0 Link encap:Ethernet HWaddr 00:21:70:B1:3F:01 inet addr: Bcast: Mask: www.opengurukul.com 107$
    • Linux: Network: sshssh : remote login programThe ssh is a remote login program like telnet to operate on remote machine.Syntax:$ ssh -l login_name host_nameExample:$ ssh -l matsya1$ www.opengurukul.com 108
    • Linux: Network: ftpftp: Internet file transfer programTo get/put files from/to internet.Example :$ ftp <remote_hostname>Username :Password :ftp> cd <remote_directory_name>ftp> lcd <local_directory_name>ftp> pwd <remote directory name>ftp> ! pwd <local directory name> www.opengurukul.com 109
    • Linux: Network: ftp : exampleftp> get file # to get single file from remote host to current boxftp> put file # to put single file from current box to remote boxftp> mget file* # to get files from remote host to current boxftp> mput file* # to put files from current box to remote boxftp> prompt # to disable promptftp> bi # binary modeftp> ha # hashftp> bye www.opengurukul.com 110
    • LINUXMODULE : COMMANDS www.opengurukul.com 111
    • Linux: Commands : locatelocate : find files by nameThe locate reads one or more databases prepared by updatedb and writes file names matching at least one of the PATTERNs to standard output, one per line.Example :$ locate php.conf/etc/httpd/conf.d/php.conf$NOTE:The database for locate is prepared by updatedb. www.opengurukul.com 112
    • Linux: Commands : updatedb.confupdatedb.conf : Do not index following file system types, names, paths.$ cat /etc/updatedb.confPRUNE_BIND_MOUNTS = "yes"PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"PRUNENAMES = ".git .hg .svn"PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/spool/squid /var/tmp"$ www.opengurukul.com 113
    • Linux: Commands : findfind – search for files in a directory hierarchyfind <STARTING DIRECTORY> <OPTIONS> <EXPRESSION>Options :–name : search for files matching a pattern–type : search for files of a particular type (f is for regular file and d is for directory)–exec : execute an action if the file is foundExample :$ find /etc -name httpd.conf -type f -exec ls -l {} ;-rw-r--r--. 1 root root 34417 Jul 9 2010 /etc/httpd/conf/httpd.conf$ www.opengurukul.com 114
    • Linux: Commands: unameuname -s : os name uname -n : node name$ uname -s $ uname -nLinux sachin-pc$ $uname : os, host, kernel & arch information$ uname -aLinux sachin-pc #1 SMP Tue Dec 16 15:25:05 EST 2008 i686 i686 i386GNU/Linux$ www.opengurukul.com 115
    • Linux: Commands: susu - run a shell with substitute user and group IDsThis command is used to switch user.To become a super user, su can be used without arguments or (su root) www.opengurukul.com 116
    • Linux: Commands: su : Example$ iduid=500(surikuma) gid=500(surikuma) groups=500(surikuma),501(dba)$ su # without any argument, ask for root passwordPassword:# iduid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),501 (dba)# su surikuma # root can switch to any user$ iduid=500(surikuma) gid=500(surikuma) groups=500(surikuma),501(dba)$ www.opengurukul.com 117
    • Linux: Commands: datedate - print or set the system date and timeSyntax : Get Date$ dateSat Sep 19 22:43:14 IST 2009$Syntax : Set Date$ date [MMDDhhmm[[CC]YY][.ss] www.opengurukul.com 118
    • Linux: Commands: calcal : displays calendarThe cal displays calendar for current month without any argsOptions:-1 : displays calendar for current month-3 : displays calendar for previous/current/next month-y : displays calendar for current year www.opengurukul.com 119
    • Linux: Commands: cal exampleExample :$ cal October 2011Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31 www.opengurukul.com 120
    • UNIXMODULE : Fedora & OpenSuse : .rpm packages : rpm and yum www.opengurukul.com 121
    • Linux: rpm : -e & -irpm -i : install package$ rpm -i <package_name.rpm>$rpm -e : erase/delete package$ rpm -e <package_name>$ www.opengurukul.com 122
    • Linux: rpm: package contentsrpm -q -a : list all packages installed on systems$ rpm -qa | grep -e ^httpdhttpd-tools-2.2.16-1.fc14.i686httpd-2.2.16-1.fc14.i686httpd-manual-2.2.16-1.fc14.noarch$ www.opengurukul.com 123
    • Linux: rpm -q -list -prpm -q –list : list files included in an installed rpm package$ rpm -q –list <package_name>$ rpm -q --list php/etc/httpd/conf.d/php.conf/usr/lib/httpd/modules/libphp5.so/var/lib/php/session/var/www/icons/php.gif$rpm -q –list -p : list files included in an rpm package$ rpm -q –list -p <package_location>$ rpm -q --list -p /var/cache/yum/updates-newkey/packages/*.rpm www.opengurukul.com 124$
    • Linux: rpm: -q -frpm -q -f <filename> : Find the Package that Contains a file.$ rpm -qf /etc/issuefedora-release-14-1.noarch$ www.opengurukul.com 125
    • Linux: yumyum : Install/update packages directly from internetYou must be a super user to install package directly from internet.You can create/update repositories information in /etc/yum/repos.d/ www.opengurukul.com 126
    • UNIXMODULE : Debin / Ubuntu LINUX : .deb packages : dpkg and apt-get www.opengurukul.com 127
    • Linux: dpkg : -i & -rdpkg -i : install package$ dpkg -i <package_name.deb>$dpkg -r : remove package$ dpkg -r <package_name>$ www.opengurukul.com 128
    • Linux: dpkg : package contentsdpkg -l : list all packages installed on systems$ dpkg -l | grep -e apache$The second filed has the package name. www.opengurukul.com 129
    • Linux: dpkg -c & -Ldpkg -L : list files included in an installed package$ dpkg -L <package_name>$ dpkg -L php/etc/httpd/conf.d/php.conf/usr/lib/httpd/modules/libphp5.so/var/lib/php/session/var/www/icons/php.gif$dpkg -c <.deb pkg name>: list files included in a deb package$ dpkg -c <deb_package_location>$ www.opengurukul.com 130
    • Linux: dpkg : -Sdpkg -S <filename> : Find the Package that Contains a file.$ dpkg -S /bin/lscoreutils: /bin/ls$ www.opengurukul.com 131
    • Linux: apt-getapt-get : Install/update packages directly from internetYou must be a super user to install package directly from internet.You can create/update repositories information in /etc/apt/sources.list www.opengurukul.com 132
    • Linux : apt-get : list, update, install, removeyum list: list packages apt-get install: install package$ yum list <package_name>* $ apt-get install <package_name>$ $To list packages matching bluefish To install bluefish editor$ yum list *bluefish* $ apt-get install bluefishapt-get update: update package apt-get remove: remove package$ apt-get update <package_name> $ apt-get remove <package_name>$ apt-get update bluefish $ To remove bluefish editor $ apt-get erase bluefish www.opengurukul.com 133
    • UNIXMODULE : LINUX www.opengurukul.com 134
    • Linux : Distribution Info/etc/*release - distribution name & version$ ls /etc/*release/etc/fedora-release /etc/redhat-release /etc/system-release$ cat /etc/*releaseFedora release 14 (Laughlin)Fedora release 14 (Laughlin)Fedora release 14 (Laughlin)$ www.opengurukul.com 135
    • Linux : LSB Distribution Infolsb_release – Distribution Information using LSB$ lsb_release -aLSB Version: :core-4.0-ia32:core-4.0-noarchDistributor ID: FedoraDescription:Fedora release 14 (Laughlin)Release: 14Codename: Laughlin$ www.opengurukul.com 136
    • Linux: ServicesService : status, start, stop, restart$ service <service_name> status | start | stop | restartExample:$ service httpd status # status of apache web server# service httpd start # start apache web server# service httpd restart # restart apache web server# service httpd stop # stop apache web server www.opengurukul.com 137
    • Linux: gzip & gunzipgunzip/gzip : GNU unzip/zipTo zip a file using GZIP.$ gzip x.tar (creates x.tar.gz)$To unzip a file using GUNZIP.$ gunzip x.tar.gz (creates uncompressed x.tar file)$ www.opengurukul.com 138
    • Linux: bzip2 & bunzip2bzip2/bunzip2 - block-sorting file compressorThe block-sorting file compressor - better than GNU zip/unzip.bzip2: To zip a file$ bzip2 x.tar (creates x.tar.bz2)$bunzip2 : To unzip a file$ bunzip2 x.tar.bz2 (creates uncompressed x.tar file) www.opengurukul.com 139$
    • Linux: tartar : tape archive commandsThe tape archive is used to combine multiple files and directories into one file.Options :-v verbose mode-f target file-c create tar-t list toc of tar-x extract files from tar www.opengurukul.com 140
    • Linux: tar : -ctar -c : create a tar file Example :Syntax : $ cd /tmptar -c -v -f <tar file> <list of $ tar -cvf team.tar team files> $ tar -cvf /tmp/team.tar teamSetup : team/$ cd /tmp team/india/$ mkdir -p team/india team/india/sachin$ mkdir -p team/australia team/australia/$ touch team/india/sachin team/australia/ricky$ touch team/australia/ricky $ www.opengurukul.com 141
    • Linux: tar : -ttar -t : list table of contentsSyntax :tar -t -v -f <tar_file>Example :$ tar -t -v -f /tmp/team.tardrwxrwxr-x sachin/sachin 0 2011-10-03 23:47 team/drwxrwxr-x sachin/sachin 0 2011-10-03 23:47 team/india/-rw-rw-r-- sachin/sachin 0 2011-10-03 23:47 team/india/sachindrwxrwxr-x sachin/sachin 0 2011-10-03 23:47 team/australia/-rw-rw-r-- sachin/sachin 0 2011-10-03 23:47 team/australia/ricky www.opengurukul.com 142$
    • Linux: tar : -xtar -x : extract files from a tar Example : file $ cd /tmpTo extract all the files $ mkdir -p new; cd new$ tar -xvf <tar file> $ tar -xvf /tmp/team.tar$ team/To extract a particular file/dir team/india/$ tar -xvf <tar file> <file path> team/india/sachin$ team/australia/ team/australia/ricky $ www.opengurukul.com 143
    • Linux: install s/w from sourcesSteps : Steps :Download .tar.bz2 file or .tar.gz. $ bunzip2 software.tar.bz2Unzip and Extract $ tar -xvf software.tarConfigure $ cd softwareCreate Makefile $ ./configureRun Make $ make cleanInstall using Make $ make all $ make install www.opengurukul.com 144
    • Linux: Support Please register yourself @ www.opengurukul.comIn case you need any support in future. www.opengurukul.com 145