SlideShare una empresa de Scribd logo
1 de 77
Welcome to UNIX and Shell Scripting workshop
                      BY
                R.Chockalingam

Contact Us
https://www.facebook.com/Karkhadotcom
Ph : 9543111174,9789989552.
UNIX

  Multitasking , Multiuser
 Operating System.
Unix operating systems are
 widely used in servers
 ,workstations and mobile
 devices.
The Unix system is composed of several components
 In addition to the kernel of an operating system – the
 development environment, libraries, documents, and
 the portable, modifiable source-code for all of these
 components
UNIX as an Operating System
All operating systems provide services for programs
 they run
Executing a new program.
Opening a file.
Reading a file.
Allocating a region of memory.
Getting the current time of day etc …
The Kernel and the Utilities

The Unix system is itself logically divided into two
 pieces: the kernel and the utilities.
The kernel is the heart of the UNIX system and
 resides in the computer's memory from the time the
 computer is turned on and booted until the time it is
 shut down.
The utilities, on the other hand, reside on the
 computer's disk and are only brought into memory as
 requested.
Architecture of the UNIX
operating system
Connecting Remotely
 You must connect to a public CS machine.

 Public Machines:

    Linux Machines (all of them are now running a Lucid build):
      juiblex, mig, totoro

 In order to find available cshosts
    Type cshosts pub on the command line for public machines or use the online list:
    http://apps.cs.utexas.edu/unixlabstatus/


 To log in, use a SSH program such as SSH Secure Shell or PuTTY (both
  available from Bevoware).
    https://www.utexas.edu/its/bevoware/download/
    When connecting, enter a machine name as follows: name.cs.utexas.edu
File Types
Two different types of files in UNIX are
1. Regular files and
2. Directories


Regular file. The most common type of file, which
 contains data of some form. There is no distinction to
 the UNIX kernel.
Directory file. A file that contains the names of other
 files and pointers to information on these files. Any
 process that has read permission for a directory file
 can read the contents of the directory, but only the
 kernel can write directly to a directory file.

Block special file. A type of file providing buffered I/O
 access in fixed-size units to devices such as disk
 drives.

Character special file. A type of file providing un
 buffered I/O access in variable-sized units to devices.
 All devices on a system are either block special files or
 character special files.
Symbolic link. A type of file that points to another
 file.

File type macros in <sys/stat.h>
Macro Type of file
S_ISREG() regular file
S_ISDIR() directory file
S_ISCHR() character special file
S_ISBLK() block special file
S_ISFIFO() pipe or FIFO
File System
 The UNIX file system consists of directories and files. Directories
  contain files or other directories. Files can be programs, text
  documents, etc.
    You can think of a directory as a folder in Windows or Macs.
    Directories contain files or other folders, just like typical operating
        systems

 The file system is organized as an inverted tree.
    the directories are branches, and the files are leaves.
    The topmost directory is /, and is called root
      all other directories and files are underneath root.



 All of a user’s files are in a home directory, /u/user
    user is the login name for that account.
    It is abbreviated ~user, mine is ~rivin

 Use the command pwd if you can’t remember which directory you are
  in.
File System Structure
The Unix file system is a hierarchical structure that
  allows users to store information by name. At the top
  of the hierarchy is the root directory, which always
  has the name /

The location of a file in the file system is called its
  path. Since the root directory is at the top of the
  hierarchy, all paths start from /.
Flags and Arguments
 command [flags] [arguments]

 command: The name of the command.
     ls lists the contents of a directory.


 flags: switches that modify the function of the base command. Flags usually begin with a "-”.
     ls –a shows all the files (including hidden files) in the current directory.
     ls –l shows files, in long-listing format, in the current directory.

     Flags can be combined.
         ls –al shows all the files (including configuration files) in long-listing format, in the current directory.
         Flags are swappable, so ls –la will do the same.


 arguments: usually the name of a file or directory to perform operations on.
     ls dirname shows all the files (in normal-listing format) in the directory dirname.


 Flags and Arguments can be combined.
     ls –al dirname shows all the files (including hidden files) in long-listing format, in the directory
        dirname.
Text Editors
 pico:

    A very easy to use text editor (the one that is used inside of alpine by default).


 vi:

    A small, fast, consistent text editor that does not have a windows interface.
    Type man vi for various commands to manipulate files.
    Type :help inside of vi to bring up the help file.


 emacs:

    Feature-rich
    Can run with a text interface from within a terminal shell, or in its own window with
     menus, etc. Type emacs to start the program and then Ctrl-h t to run a tutorial.
    Emacs will run in its own window when running Xwindows. Just type emacs and the
     window will come up.
Basic UNIX Commands
 ls directory: Lists the contents of the directory. If no directory name is given, it will list the
   files in the directory you are in.

 cd directory: Change from current directory to directory. If no name is given, it will go to
   your home directory.

 mkdir dir1: Create a directory named dir1. Multiple directory names can be given.

 cp file1 file2: Make a copy of file1 and name it file2. If file2 already exists, it will be
   overwritten.

 rm file1: Remove the file named file1. Multiple filenames can be given.

 mv file1 file2: Rename file1 as file2
 mv file1 directory2: Move file1 into directory2.
      For example, mv project1 CS310 would move the file project1 into the directory CS310
          The directory CS310 must be created first.


 .snapshot: Grab the most recent version of a file if you accidentally deleted it.
Creating a file
cat>firstfile



To read a file :


 %cat > firstfile
Creating a Directory

Creating directories permits you to organize your
 files. The command
 mkdir project1
Basic Commands
man [section] <command> Look up a command
pwd Display current directory
ls [-al] List directory contents
cd<directory> Change Directory
rm <filename> Delete file
cp <filename> <ending
filename>
Copy file to new location
mv <filename> <ending
filename>
Move file to new location
cat <filename> Display entire file
more <filename> Display file one page at a time
wc [-l|w|c] <filename> Return file statistics: number
 of words, lines, and
ps [ax or ef] List processes running on the system
kill -<signal> < process ID> Send end signal to a
 running process
Editor
Vi
emacs


vi is the classic screen-editing program for Unix
vi test.txt
i Changes to insert mode
or a (after the character under the cursor)
:w Return Save the file
:w<filename> Save the file to a new name
:q Return To exit vi
Command
:q! Return Quit without saving
Insert Esc key Changes to command mode
mode
Backspace and Delete keys Backspaces or deletes, but
 only for data
|       The Pipe
|
(shift-)
takes the output of one command and feeds it to another command.


less is a pager (shows you a text file one page at a time).
cshosts shows you all the hosts in CS (many pages).

cshosts | less
takes the output of cshosts (many pages) and runs less on it.


grep string filename looks for instances of string inside of filename.

cshosts | grep mo
tells you the machine names returned by cshosts that contain instances of “mo”.
More UNIX Commands
X acroread filename.pdf: Read a .pdf file. If no filename is given, it
  will open the program with no initial file.
   - xpdf can also be used.
X gv filename.ps: If you ever get a .ps (postscript) file, use this to view
  it. If no name is given, it will open the program with no initial file.
X gimp filename: View a graphics file (.jpg or .gif).

 chkquota: Check your disk-space usage in megabytes.

 gzip filename: Zip a file to conserve space.
 gunzip filename: Unzip a file that is zipped.
 zip/unzip filename: Winzip compatible

 ps uxw (ps –u user): Check the processes you have running.
 kill 14083: Kill the process with PID# 14083.
Electronic Mail
 Your email address is your_login@cs.utexas.edu.

 Mail Programs:
  There are literally hundreds of mail readers freely available for UNIX.
    Staff supports alpine, mutt, and thunderbird.


 Reading mail:
  Typing alpine with no username puts you into the Alpine mail program.
    Selecting Message Index will show you the contents of your mailbox.


 Sending mail:
  alpine username sends mail to the person with the login username. If it’s a
  CS login, you can leave off the domain name. Otherwise, use the entire email
  address: (name@domain.com).

 Finding addresses:
  phone name will try to find someone with that name in CS.
Printing
 All printers are numbered in the CS department as lw# (for example, lw4).
 A banner page is printed with your file to keep users’ work separated.

 lpr
   lpr –Plw4 file1 will send file1 to printer number 4, in the Taylor basement lab.

 lpq
   lpq –Plw4 will list job numbers of all the files currently in lw4’s print queue (those waiting to
   be printed).

 lprm
   lprm –Plw4 900 will remove job number 900 from lw4’s print queue (the job number can be
   found with lpq).

 less /lusr/share/etc/printcap gives a list of printers and their locations

 Printing FAQ:
   http://www.cs.utexas.edu/facilities/faq
   http://www.cs.utexas.edu/facilities/documentation/printing-options
The UNIX System Shell Programming
Steps to Create Shell Programs
Specify shell to execute program
 Script must begin with #! (pronounced “shebang”)
   to identify shell to be executed
Examples:
    #! /bin/sh         (defaults to bash)
    #! /bin/bash
    #! /bin/csh
    #! /usr/bin/tcsh
Make the shell program executable
 Use the “chmod” command to make the
  program/script file executable                     30
Example: “hello” Script
#! /bin/csh
echo "Hello $USER"
echo "This machine is `uname -n`"
echo "The calendar for this month is:"
cal
echo "You are running these processes:"




                                           Karkha.com
ps

                                          31
Example script output
% chmod u+x hello
% ./hello
Hello ege!
This machine is turing
The calendar for this month is
   February 2008
 S M Tu W Th F S
 1 2 3 4 5 6 7
 8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
You are running these processes:
   PID TTY       TIME CMD
 24861 pts/18    0:00 hello.csh
 24430 pts/18    0:00 csh

                                   Karkha.
                  32                  com
Shell logic structures needed for program
Basic
       Logic Structures
  development:

  Sequential logic
  User input
  Decision logic
  Looping logic
  Case logic




                                            Karkha.
                33                             com
Input to a C shell script
 Reading/prompting for user input
Providing input as command line arguments
Accessing contents of files




                                             Karkha.
              34                                com
Reading user input with $<
Use a special C shell variable:
      $<

Reads a line from terminal (stdin)
 up to, but not including the new line




                                         Karkha.
              35                            com
Example: Accepting User Input
#! /bin/csh
echo "What is your name?"
set name = $<
echo Greetings to you, $name
echo "See you soon"




                               Karkha.
           36                     com
Example: greetings User Input
% chmod u+x
            Accepting
% ./greetings            User entered Laura
                         Flowers
What is your name?
Laura Flowers
Greetings to you, Laura Flowers
See you soon




                                              Karkha.
              37                                 com
Command line arguments
Use arguments to modify script behavior


command line arguments become
  positional parameters to C shell script

positional parameters are numbered
  variables:   $1, $2, $3 …




                                            Karkha.
               38                              com
Command line arguments
     Meaning
$0          name of the script
$1, $2            first and second parameter
${10}       10th parameter
                 { } prevents “$1”
    misunderstanding
$*          all positional parameters
$#argv      the number of arguments


                                               Karkha.
              39                                  com
Example: Command Line
Arguments
#! /bin/csh
# Usage: greetings name1 name2
# Input: name1 and name2
echo $0 to you $1 $2
echo Today is `date` $1 $2
echo Good Bye $1 $2




                                 Karkha.
           40                       com
Example: Command Line
Arguments
                             $0 => greetings
                               $1 => Mark
                              $2 => Flowers


% chmod u+x greetings
% ./greetings Mark Flowers
./greetings to you Mark Flowers
Today is Mon Feb 16 14:18:03 CST
 2008
Good Bye Mark Flowers

                                               Karkha.
           41                                     com
Decision logic
if Statement: simplest forms


 if ( expression ) command



 if ( expression ) then
   command(s)
 endif


                                Karkha.
             42                    com
Decision Statement
if-then-else
              logic
 if ( expression ) then
   command(s)
 else
   command(s)
 endif




                          Karkha.
           43                com
Decision Statement
if-then-else
              logic
 if ( expression ) then
   command(s)
 else if ( expression ) then
   command(s)
 else
   command(s)
 endif

                               Karkha.
           44                     com
Basic Operators in Expressions
              Meaning
       ()       grouping
       !        Logical “not”
    > >= < <=   greater than, less than
     == !=      equal to, not equal to

       ||       Logical “or”
       &&       Logical “and”


                                          Karkha.
         45                                  com
Expression examples$2
if ( $1 == “next” ) echo


if ( $#argv != 0 ) then
    …
 endif

if ( $#argv > 0 && $#argv < 5) then
    …
 endif
                                       Karkha.
          46                              com
Example: Command Line
Arguments
#! /bin/csh
if ( $#argv == 0 ) then
   echo -n "Enter time in minutes: "
   @ min = $<
else
   @ min = $1
endif
@ sec = $min * 60
echo “$min minutes is $sec seconds”
                                       Karkha.
           47                             com
Example: Reading file contents
#! /bin/csh
# Usage: lookup nameOrNumber
set list = "users.txt"
if ( $#argv == 0 ) then
   echo -n "Enter name OR z-id: "
   set name = $<
else
   set name = $*
endif
grep -i "$name" $list
if ( $status ) echo "$name not found"   Karkha.
            48                             com
File Testing operators)
Syntax: if ( -opr filename

    opr   Meaning
     r    Read access
    w     Write access
    x     Execute access
     e    Existence
     z    Zero length
     f    Ordinary file
    d     directory

                              Karkha.
             49                  com
Example: File Testing
if ( -e $1 ) then
     echo $1 exists
     if ( -f $1 ) then
          echo $1 is an ordinary file
     else
          echo $1 is NOT ordinary
 file
     endif
else
     echo $1 does NOT exist
endif
                                        Karkha.
           50                              com
C Shell looping constructs
predetermined iterations
 repeat
 foreach



condition-based iterations
 while



                              Karkha.
             51                  com
Fixed number iterations
Syntax:

  repeat number command

  executes “command” “number” times


Examples:
 repeat 5 ls
 repeat 2 echo “go home”

                                       Karkha.
             52                           com
The foreach Statement
  foreach name ( wordlist )
    commands
  end

wordlist is:
  list of words, or
  multi-valued variable
each time through,
 foreach assigns the next item in wordlist to
 the variable $name
                                                Karkha.
                53                                 com
Example: foreach Statement
 foreach word ( one two three )
    echo $word
 end

or


 set list = ( one two three )
 foreach word ( $list )
    echo $word
 end
                                  Karkha.
          54                         com
Loops with foreach
 useful to process result of command,
  one at a time

Example:
#! /bin/csh
@ sum = 0
foreach file (`ls`)
         set size = `cat $file | wc -c`
         echo "Counting: $file ($size)"
         @ sum = $sum + $size
end
echo Sum: $sum                            Karkha.
                  55                         com
The while Statement
  while ( expression )
     commands
  end

use when the number of iterations is not
 known in advance
execute ‘commands’ when the expression is
 true
terminates when the expression becomes
 false
                                             Karkha.
             56                                 com
Example: while
#! /bin/csh
@ var = 5
while ( $var > 0 )
     echo $var
     @ var = $var – 1
end




                        Karkha.
           57              com
Example: while
#! /bin/csh
echo -n "Enter directory to list: "
set dirname = $<
while ( ! -d $dirname )
    echo "$dirname is not directory"
    echo -n "Enter directory to list:
 "
    set dirname = $<
end
ls $dirname
                                        Karkha.
           58                              com
loop control
 break
 ends loop, i.e. breaks out of current loop

continue
 ends current iteration of loop, continues with
 next iteration




                                                  Karkha.
              59                                     com
loop control example
 #! /bin/csh
while (1)
        echo -n "want more?   "
        set answer = $<
        if ($answer == "y")   echo
 "fine"
        if ($answer == "n")   break
        if ($answer == "c")   continue
        echo "now we are at   the end"
end
                                         Karkha.
           60                               com
loop control example
 #! /bin/csh
while ( 1 )
    echo -n "Enter directory to list:
 "
    set dirname = $<
    if ( -d $dirname ) break
    echo "$dirname is not directory"
end
ls $dirname

                                        Karkha.
           61                              com
The when a variable can take different
Use
     switch Statement
 values
Use switch statement to process different
 cases (case statement)

Can replace a long sequence of
  if-then-else statements




                                             Karkha.
              62                                com
The switch Statement
switch ( string ) C shell compares
 case pattern1:   ‘string’ to each ‘pattern’
                  until it finds a match
     command(s)
 breaksw
                  When a match is
 case pattern2:
                  found, execute the
     command(s)   command(s)
 breaksw
endsw
                  … until breaksw


                                               Karkha.
          63                                      com
The switch Statement
switch (string)
 case pattern1:
     command(s)
 breaksw
 case pattern2:
     command(s)
 breaksw          When a match is not
 default:         found, execute the
                  commands following the
     command(s)   default label
 breaksw
endsw                                      Karkha.
          64                                  com
Example: switch
switch ($var)
        case one:
                echo it is 1
        breaksw
        case two:
                echo it is 2
        breaksw
        default:
                echo it is $var
        breaksw
endsw                             Karkha.
           65                        com
The switch Statement no default,
if no pattern matches and there is
 then nothing gets executed

do not omit the breaksw statement !
 If you omit the breaksw statement, all the
   commands
 under the next case pattern are executed until a
 breaksw or endsw statement is encountered

pattern may contain wildcards:
 *, ?, []
                                                    Karkha.
               66                                      com
Example: switch greeting
#! /bin/csh
# Usage: greeting name
# examines time of day for greeting
set hour=`date`
switch ($hour[4])
    case 0*:
    case 1[01]*:
          set greeting=morning ; breaksw
    case 1[2-7]*:
          set greeting=afternoon ; breaksw
    default:
          set greeting=evening
endsw
echo Good $greeting $1
                                             Karkha.
             67                                 com
Example C Shell program
    AVAILABLE OPTIONS
   *******************
 [1] Display today's date
 [2] How many people are logged on
 [3] How many user accounts exist
 [4] Exit
 Enter Your Choice [1-4]:




                                     Karkha.
            68                          com
userutil shell script 1 of 2
#! /bin/csh
# Usage: userutil
while (1)
  echo "AVAILABLE OPTIONS"
  echo "*******************"
  echo "[1] Display today's date"
  echo "[2] How many people are logged on"
  echo "[3] How many user accounts exist"
  echo "[4] Exit"
  echo "Enter Your Choice [1-4]:"



                                             Karkha.
              69                                com
userutil shell script 2 of 2
   set answer = $<
    switch ($answer)
       case "1":
          echo `date`; breaksw
       case "2":
          echo `users | wc -w` users are logged in
          breaksw
       case "3":
          echo `cat /etc/passwd | wc -l` users exists
          breaksw
       case "4":
          echo "BYE"
          break
          breaksw
    endsw
end             # end of while

                                                        Karkha.
                70                                         com
Advanced C Shell Programming
Quoting
Here
Debugging
Trapping Signals


Functions ?
  calling other scripts
  exec, source, eval



                           Karkha.
               71             com
Quoting for marking a section of a
mechanism
  command for special processing:

  command substitution: `...`
  double quotes: “…“
  single quotes: ‘…‘
  backslash: 




                                     Karkha.
              72                        com
Doublebreakup of string into words
prevents
          quotes
turn off the special meaning of most wildcard
 characters and the single quote
  $ character keeps its meaning
  ! history references keeps its meaning


Examples:
 echo "* isn't a wildcard inside quotes"
 echo "my path is $PATH"

                                                 Karkha.
              73                                    com
Single quotes and command
wildcards, variables
 substitutions are all treated as ordinary text
history references are recognized


Examples:
 echo '*'
 echo '$cwd'
 echo '`echo hello`'
 echo 'hi there !'

                                                  Karkha.
               74                                    com
backslash
backslash character 
  treats following character literally

Examples:
 echo $ is a dollar sign
 echo  is a backslash




                                         Karkha.
               75                           com
Debugging Scripts
% csh –n scriptname
parse commands but do not execute them


% csh –v scriptname
Display each line of the script before execution


% csh –x scriptname
Displays each line of the script after variable
 substitutions and before execution

can also be added to shebang line !
                                                    Karkha.
                76                                     com
Calling other scripts
as subshell, via:
    csh scriptname
    scriptname


subshell does not see current shell’s variables
subshell sees current environment variables




                                                   Karkha.
              77                                      com

Más contenido relacionado

La actualidad más candente

Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & CommandsMohit Belwal
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)anandvaidya
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Wave Digitech
 
Linux Administration
Linux AdministrationLinux Administration
Linux AdministrationHarish1983
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Scriptsbmguys
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumarymentorsnet
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemSadia Bashir
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)Rodrigo Maia
 
Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)meashi
 
1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_CommandsGautam Raja
 

La actualidad más candente (20)

Know the UNIX Commands
Know the UNIX CommandsKnow the UNIX Commands
Know the UNIX Commands
 
Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & Commands
 
Unix training session 1
Unix training   session 1Unix training   session 1
Unix training session 1
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Script
 
Nithi
NithiNithi
Nithi
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumary
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Linux commands
Linux commandsLinux commands
Linux commands
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)
 
1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands
 
Os lab manual
Os lab manualOs lab manual
Os lab manual
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 

Destacado

Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014iimjobs and hirist
 
Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslogashok191
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2Nihar Ranjan Paital
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1Nihar Ranjan Paital
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanshipbokonen
 
Module 13 - Troubleshooting
Module 13 - TroubleshootingModule 13 - Troubleshooting
Module 13 - TroubleshootingT. J. Saotome
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle TroubleshootingHector Martinez
 
Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tipsBert Van Vreckem
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training Nancy Thomas
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingDan Morrill
 
Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Dirk Nachbar
 
25 Apache Performance Tips
25 Apache Performance Tips25 Apache Performance Tips
25 Apache Performance TipsMonitis_Inc
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshootingNathan Winters
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sMydbops
 
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksCloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksScott Jenner
 

Destacado (20)

Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslog
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
Module 13 - Troubleshooting
Module 13 - TroubleshootingModule 13 - Troubleshooting
Module 13 - Troubleshooting
 
APACHE
APACHEAPACHE
APACHE
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle Troubleshooting
 
Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tips
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2
 
25 Apache Performance Tips
25 Apache Performance Tips25 Apache Performance Tips
25 Apache Performance Tips
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshooting
 
Tomcat next
Tomcat nextTomcat next
Tomcat next
 
Tomcat
TomcatTomcat
Tomcat
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA's
 
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksCloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
 

Similar a Karkha unix shell scritping

Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338Cam YP Co., Ltd
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338Cam YP Co., Ltd
 
Operating systems unix
Operating systems   unixOperating systems   unix
Operating systems unixAchu dhan
 
84640411 study-of-unix-os
84640411 study-of-unix-os84640411 study-of-unix-os
84640411 study-of-unix-oshomeworkping3
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
linux-lecture4.ppt
linux-lecture4.pptlinux-lecture4.ppt
linux-lecture4.pptLuigysToro
 
Unix Basics
Unix BasicsUnix Basics
Unix BasicsDr.Ravi
 
Chapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsChapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsMeenalJabde
 
Linux Notes-1.pdf
Linux Notes-1.pdfLinux Notes-1.pdf
Linux Notes-1.pdfasif64436
 
Unix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiUnix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiPriyadarshini648418
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command ShellTushar B Kute
 
Basics of UNIX Commands
Basics of UNIX CommandsBasics of UNIX Commands
Basics of UNIX CommandsSubra Das
 
linux-file-system01.ppt
linux-file-system01.pptlinux-file-system01.ppt
linux-file-system01.pptMeesanRaza
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scriptsPrashantTechment
 

Similar a Karkha unix shell scritping (20)

Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338
 
Operating systems unix
Operating systems   unixOperating systems   unix
Operating systems unix
 
84640411 study-of-unix-os
84640411 study-of-unix-os84640411 study-of-unix-os
84640411 study-of-unix-os
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
linux-lecture4.ppt
linux-lecture4.pptlinux-lecture4.ppt
linux-lecture4.ppt
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
UNIX.pptx
UNIX.pptxUNIX.pptx
UNIX.pptx
 
Basics of unix
Basics of unixBasics of unix
Basics of unix
 
Linux Basics
Linux BasicsLinux Basics
Linux Basics
 
Chapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix ConceptsChapter 2 Introduction to Unix Concepts
Chapter 2 Introduction to Unix Concepts
 
Linux Notes-1.pdf
Linux Notes-1.pdfLinux Notes-1.pdf
Linux Notes-1.pdf
 
Unix
UnixUnix
Unix
 
Unix environment [autosaved]
Unix environment [autosaved]Unix environment [autosaved]
Unix environment [autosaved]
 
Unix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiUnix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basi
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
Linux
LinuxLinux
Linux
 
Basics of UNIX Commands
Basics of UNIX CommandsBasics of UNIX Commands
Basics of UNIX Commands
 
linux-file-system01.ppt
linux-file-system01.pptlinux-file-system01.ppt
linux-file-system01.ppt
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
 

Último

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Karkha unix shell scritping

  • 1. Welcome to UNIX and Shell Scripting workshop BY R.Chockalingam Contact Us https://www.facebook.com/Karkhadotcom Ph : 9543111174,9789989552.
  • 2.
  • 3. UNIX  Multitasking , Multiuser Operating System. Unix operating systems are widely used in servers ,workstations and mobile devices.
  • 4. The Unix system is composed of several components In addition to the kernel of an operating system – the development environment, libraries, documents, and the portable, modifiable source-code for all of these components
  • 5. UNIX as an Operating System All operating systems provide services for programs they run Executing a new program. Opening a file. Reading a file. Allocating a region of memory. Getting the current time of day etc …
  • 6. The Kernel and the Utilities The Unix system is itself logically divided into two pieces: the kernel and the utilities. The kernel is the heart of the UNIX system and resides in the computer's memory from the time the computer is turned on and booted until the time it is shut down. The utilities, on the other hand, reside on the computer's disk and are only brought into memory as requested.
  • 7. Architecture of the UNIX operating system
  • 8. Connecting Remotely  You must connect to a public CS machine.  Public Machines:  Linux Machines (all of them are now running a Lucid build): juiblex, mig, totoro  In order to find available cshosts  Type cshosts pub on the command line for public machines or use the online list:  http://apps.cs.utexas.edu/unixlabstatus/  To log in, use a SSH program such as SSH Secure Shell or PuTTY (both available from Bevoware).  https://www.utexas.edu/its/bevoware/download/  When connecting, enter a machine name as follows: name.cs.utexas.edu
  • 9. File Types Two different types of files in UNIX are 1. Regular files and 2. Directories Regular file. The most common type of file, which contains data of some form. There is no distinction to the UNIX kernel.
  • 10. Directory file. A file that contains the names of other files and pointers to information on these files. Any process that has read permission for a directory file can read the contents of the directory, but only the kernel can write directly to a directory file. Block special file. A type of file providing buffered I/O access in fixed-size units to devices such as disk drives. Character special file. A type of file providing un buffered I/O access in variable-sized units to devices. All devices on a system are either block special files or character special files.
  • 11. Symbolic link. A type of file that points to another file. File type macros in <sys/stat.h> Macro Type of file S_ISREG() regular file S_ISDIR() directory file S_ISCHR() character special file S_ISBLK() block special file S_ISFIFO() pipe or FIFO
  • 12. File System  The UNIX file system consists of directories and files. Directories contain files or other directories. Files can be programs, text documents, etc.  You can think of a directory as a folder in Windows or Macs.  Directories contain files or other folders, just like typical operating systems  The file system is organized as an inverted tree.  the directories are branches, and the files are leaves.  The topmost directory is /, and is called root  all other directories and files are underneath root.  All of a user’s files are in a home directory, /u/user  user is the login name for that account.  It is abbreviated ~user, mine is ~rivin  Use the command pwd if you can’t remember which directory you are in.
  • 13. File System Structure The Unix file system is a hierarchical structure that allows users to store information by name. At the top of the hierarchy is the root directory, which always has the name / The location of a file in the file system is called its path. Since the root directory is at the top of the hierarchy, all paths start from /.
  • 14.
  • 15. Flags and Arguments  command [flags] [arguments]  command: The name of the command.  ls lists the contents of a directory.  flags: switches that modify the function of the base command. Flags usually begin with a "-”.  ls –a shows all the files (including hidden files) in the current directory.  ls –l shows files, in long-listing format, in the current directory.  Flags can be combined.  ls –al shows all the files (including configuration files) in long-listing format, in the current directory.  Flags are swappable, so ls –la will do the same.  arguments: usually the name of a file or directory to perform operations on.  ls dirname shows all the files (in normal-listing format) in the directory dirname.  Flags and Arguments can be combined.  ls –al dirname shows all the files (including hidden files) in long-listing format, in the directory dirname.
  • 16. Text Editors  pico:  A very easy to use text editor (the one that is used inside of alpine by default).  vi:  A small, fast, consistent text editor that does not have a windows interface.  Type man vi for various commands to manipulate files.  Type :help inside of vi to bring up the help file.  emacs:  Feature-rich  Can run with a text interface from within a terminal shell, or in its own window with menus, etc. Type emacs to start the program and then Ctrl-h t to run a tutorial.  Emacs will run in its own window when running Xwindows. Just type emacs and the window will come up.
  • 17. Basic UNIX Commands  ls directory: Lists the contents of the directory. If no directory name is given, it will list the files in the directory you are in.  cd directory: Change from current directory to directory. If no name is given, it will go to your home directory.  mkdir dir1: Create a directory named dir1. Multiple directory names can be given.  cp file1 file2: Make a copy of file1 and name it file2. If file2 already exists, it will be overwritten.  rm file1: Remove the file named file1. Multiple filenames can be given.  mv file1 file2: Rename file1 as file2  mv file1 directory2: Move file1 into directory2.  For example, mv project1 CS310 would move the file project1 into the directory CS310  The directory CS310 must be created first.  .snapshot: Grab the most recent version of a file if you accidentally deleted it.
  • 18. Creating a file cat>firstfile To read a file : %cat > firstfile
  • 19. Creating a Directory Creating directories permits you to organize your files. The command mkdir project1
  • 20. Basic Commands man [section] <command> Look up a command pwd Display current directory ls [-al] List directory contents cd<directory> Change Directory rm <filename> Delete file cp <filename> <ending filename> Copy file to new location mv <filename> <ending filename> Move file to new location
  • 21. cat <filename> Display entire file more <filename> Display file one page at a time wc [-l|w|c] <filename> Return file statistics: number of words, lines, and ps [ax or ef] List processes running on the system kill -<signal> < process ID> Send end signal to a running process
  • 22. Editor Vi emacs vi is the classic screen-editing program for Unix vi test.txt
  • 23. i Changes to insert mode or a (after the character under the cursor) :w Return Save the file :w<filename> Save the file to a new name :q Return To exit vi Command :q! Return Quit without saving Insert Esc key Changes to command mode mode Backspace and Delete keys Backspaces or deletes, but only for data
  • 24.
  • 25. | The Pipe | (shift-) takes the output of one command and feeds it to another command. less is a pager (shows you a text file one page at a time). cshosts shows you all the hosts in CS (many pages). cshosts | less takes the output of cshosts (many pages) and runs less on it. grep string filename looks for instances of string inside of filename. cshosts | grep mo tells you the machine names returned by cshosts that contain instances of “mo”.
  • 26. More UNIX Commands X acroread filename.pdf: Read a .pdf file. If no filename is given, it will open the program with no initial file. - xpdf can also be used. X gv filename.ps: If you ever get a .ps (postscript) file, use this to view it. If no name is given, it will open the program with no initial file. X gimp filename: View a graphics file (.jpg or .gif).  chkquota: Check your disk-space usage in megabytes.  gzip filename: Zip a file to conserve space.  gunzip filename: Unzip a file that is zipped.  zip/unzip filename: Winzip compatible  ps uxw (ps –u user): Check the processes you have running.  kill 14083: Kill the process with PID# 14083.
  • 27. Electronic Mail  Your email address is your_login@cs.utexas.edu.  Mail Programs: There are literally hundreds of mail readers freely available for UNIX.  Staff supports alpine, mutt, and thunderbird.  Reading mail: Typing alpine with no username puts you into the Alpine mail program.  Selecting Message Index will show you the contents of your mailbox.  Sending mail: alpine username sends mail to the person with the login username. If it’s a CS login, you can leave off the domain name. Otherwise, use the entire email address: (name@domain.com).  Finding addresses: phone name will try to find someone with that name in CS.
  • 28. Printing  All printers are numbered in the CS department as lw# (for example, lw4).  A banner page is printed with your file to keep users’ work separated.  lpr lpr –Plw4 file1 will send file1 to printer number 4, in the Taylor basement lab.  lpq lpq –Plw4 will list job numbers of all the files currently in lw4’s print queue (those waiting to be printed).  lprm lprm –Plw4 900 will remove job number 900 from lw4’s print queue (the job number can be found with lpq).  less /lusr/share/etc/printcap gives a list of printers and their locations  Printing FAQ: http://www.cs.utexas.edu/facilities/faq http://www.cs.utexas.edu/facilities/documentation/printing-options
  • 29. The UNIX System Shell Programming
  • 30. Steps to Create Shell Programs Specify shell to execute program Script must begin with #! (pronounced “shebang”) to identify shell to be executed Examples: #! /bin/sh (defaults to bash) #! /bin/bash #! /bin/csh #! /usr/bin/tcsh Make the shell program executable Use the “chmod” command to make the program/script file executable 30
  • 31. Example: “hello” Script #! /bin/csh echo "Hello $USER" echo "This machine is `uname -n`" echo "The calendar for this month is:" cal echo "You are running these processes:" Karkha.com ps 31
  • 32. Example script output % chmod u+x hello % ./hello Hello ege! This machine is turing The calendar for this month is February 2008 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 You are running these processes: PID TTY TIME CMD 24861 pts/18 0:00 hello.csh 24430 pts/18 0:00 csh Karkha. 32 com
  • 33. Shell logic structures needed for program Basic Logic Structures development: Sequential logic User input Decision logic Looping logic Case logic Karkha. 33 com
  • 34. Input to a C shell script Reading/prompting for user input Providing input as command line arguments Accessing contents of files Karkha. 34 com
  • 35. Reading user input with $< Use a special C shell variable: $< Reads a line from terminal (stdin) up to, but not including the new line Karkha. 35 com
  • 36. Example: Accepting User Input #! /bin/csh echo "What is your name?" set name = $< echo Greetings to you, $name echo "See you soon" Karkha. 36 com
  • 37. Example: greetings User Input % chmod u+x Accepting % ./greetings User entered Laura Flowers What is your name? Laura Flowers Greetings to you, Laura Flowers See you soon Karkha. 37 com
  • 38. Command line arguments Use arguments to modify script behavior command line arguments become positional parameters to C shell script positional parameters are numbered variables: $1, $2, $3 … Karkha. 38 com
  • 39. Command line arguments Meaning $0 name of the script $1, $2 first and second parameter ${10} 10th parameter { } prevents “$1” misunderstanding $* all positional parameters $#argv the number of arguments Karkha. 39 com
  • 40. Example: Command Line Arguments #! /bin/csh # Usage: greetings name1 name2 # Input: name1 and name2 echo $0 to you $1 $2 echo Today is `date` $1 $2 echo Good Bye $1 $2 Karkha. 40 com
  • 41. Example: Command Line Arguments $0 => greetings $1 => Mark $2 => Flowers % chmod u+x greetings % ./greetings Mark Flowers ./greetings to you Mark Flowers Today is Mon Feb 16 14:18:03 CST 2008 Good Bye Mark Flowers Karkha. 41 com
  • 42. Decision logic if Statement: simplest forms if ( expression ) command if ( expression ) then command(s) endif Karkha. 42 com
  • 43. Decision Statement if-then-else logic if ( expression ) then command(s) else command(s) endif Karkha. 43 com
  • 44. Decision Statement if-then-else logic if ( expression ) then command(s) else if ( expression ) then command(s) else command(s) endif Karkha. 44 com
  • 45. Basic Operators in Expressions Meaning () grouping ! Logical “not” > >= < <= greater than, less than == != equal to, not equal to || Logical “or” && Logical “and” Karkha. 45 com
  • 46. Expression examples$2 if ( $1 == “next” ) echo if ( $#argv != 0 ) then … endif if ( $#argv > 0 && $#argv < 5) then … endif Karkha. 46 com
  • 47. Example: Command Line Arguments #! /bin/csh if ( $#argv == 0 ) then echo -n "Enter time in minutes: " @ min = $< else @ min = $1 endif @ sec = $min * 60 echo “$min minutes is $sec seconds” Karkha. 47 com
  • 48. Example: Reading file contents #! /bin/csh # Usage: lookup nameOrNumber set list = "users.txt" if ( $#argv == 0 ) then echo -n "Enter name OR z-id: " set name = $< else set name = $* endif grep -i "$name" $list if ( $status ) echo "$name not found" Karkha. 48 com
  • 49. File Testing operators) Syntax: if ( -opr filename opr Meaning r Read access w Write access x Execute access e Existence z Zero length f Ordinary file d directory Karkha. 49 com
  • 50. Example: File Testing if ( -e $1 ) then echo $1 exists if ( -f $1 ) then echo $1 is an ordinary file else echo $1 is NOT ordinary file endif else echo $1 does NOT exist endif Karkha. 50 com
  • 51. C Shell looping constructs predetermined iterations repeat foreach condition-based iterations while Karkha. 51 com
  • 52. Fixed number iterations Syntax: repeat number command executes “command” “number” times Examples: repeat 5 ls repeat 2 echo “go home” Karkha. 52 com
  • 53. The foreach Statement foreach name ( wordlist ) commands end wordlist is: list of words, or multi-valued variable each time through, foreach assigns the next item in wordlist to the variable $name Karkha. 53 com
  • 54. Example: foreach Statement foreach word ( one two three ) echo $word end or set list = ( one two three ) foreach word ( $list ) echo $word end Karkha. 54 com
  • 55. Loops with foreach  useful to process result of command, one at a time Example: #! /bin/csh @ sum = 0 foreach file (`ls`) set size = `cat $file | wc -c` echo "Counting: $file ($size)" @ sum = $sum + $size end echo Sum: $sum Karkha. 55 com
  • 56. The while Statement while ( expression ) commands end use when the number of iterations is not known in advance execute ‘commands’ when the expression is true terminates when the expression becomes false Karkha. 56 com
  • 57. Example: while #! /bin/csh @ var = 5 while ( $var > 0 ) echo $var @ var = $var – 1 end Karkha. 57 com
  • 58. Example: while #! /bin/csh echo -n "Enter directory to list: " set dirname = $< while ( ! -d $dirname ) echo "$dirname is not directory" echo -n "Enter directory to list: " set dirname = $< end ls $dirname Karkha. 58 com
  • 59. loop control break ends loop, i.e. breaks out of current loop continue ends current iteration of loop, continues with next iteration Karkha. 59 com
  • 60. loop control example #! /bin/csh while (1) echo -n "want more? " set answer = $< if ($answer == "y") echo "fine" if ($answer == "n") break if ($answer == "c") continue echo "now we are at the end" end Karkha. 60 com
  • 61. loop control example #! /bin/csh while ( 1 ) echo -n "Enter directory to list: " set dirname = $< if ( -d $dirname ) break echo "$dirname is not directory" end ls $dirname Karkha. 61 com
  • 62. The when a variable can take different Use switch Statement values Use switch statement to process different cases (case statement) Can replace a long sequence of if-then-else statements Karkha. 62 com
  • 63. The switch Statement switch ( string ) C shell compares case pattern1: ‘string’ to each ‘pattern’ until it finds a match command(s) breaksw When a match is case pattern2: found, execute the command(s) command(s) breaksw endsw … until breaksw Karkha. 63 com
  • 64. The switch Statement switch (string) case pattern1: command(s) breaksw case pattern2: command(s) breaksw When a match is not default: found, execute the commands following the command(s) default label breaksw endsw Karkha. 64 com
  • 65. Example: switch switch ($var) case one: echo it is 1 breaksw case two: echo it is 2 breaksw default: echo it is $var breaksw endsw Karkha. 65 com
  • 66. The switch Statement no default, if no pattern matches and there is then nothing gets executed do not omit the breaksw statement ! If you omit the breaksw statement, all the commands under the next case pattern are executed until a breaksw or endsw statement is encountered pattern may contain wildcards: *, ?, [] Karkha. 66 com
  • 67. Example: switch greeting #! /bin/csh # Usage: greeting name # examines time of day for greeting set hour=`date` switch ($hour[4]) case 0*: case 1[01]*: set greeting=morning ; breaksw case 1[2-7]*: set greeting=afternoon ; breaksw default: set greeting=evening endsw echo Good $greeting $1 Karkha. 67 com
  • 68. Example C Shell program AVAILABLE OPTIONS ******************* [1] Display today's date [2] How many people are logged on [3] How many user accounts exist [4] Exit Enter Your Choice [1-4]: Karkha. 68 com
  • 69. userutil shell script 1 of 2 #! /bin/csh # Usage: userutil while (1) echo "AVAILABLE OPTIONS" echo "*******************" echo "[1] Display today's date" echo "[2] How many people are logged on" echo "[3] How many user accounts exist" echo "[4] Exit" echo "Enter Your Choice [1-4]:" Karkha. 69 com
  • 70. userutil shell script 2 of 2 set answer = $< switch ($answer) case "1": echo `date`; breaksw case "2": echo `users | wc -w` users are logged in breaksw case "3": echo `cat /etc/passwd | wc -l` users exists breaksw case "4": echo "BYE" break breaksw endsw end # end of while Karkha. 70 com
  • 71. Advanced C Shell Programming Quoting Here Debugging Trapping Signals Functions ? calling other scripts exec, source, eval Karkha. 71 com
  • 72. Quoting for marking a section of a mechanism command for special processing: command substitution: `...` double quotes: “…“ single quotes: ‘…‘ backslash: Karkha. 72 com
  • 73. Doublebreakup of string into words prevents quotes turn off the special meaning of most wildcard characters and the single quote $ character keeps its meaning ! history references keeps its meaning Examples: echo "* isn't a wildcard inside quotes" echo "my path is $PATH" Karkha. 73 com
  • 74. Single quotes and command wildcards, variables substitutions are all treated as ordinary text history references are recognized Examples: echo '*' echo '$cwd' echo '`echo hello`' echo 'hi there !' Karkha. 74 com
  • 75. backslash backslash character treats following character literally Examples: echo $ is a dollar sign echo is a backslash Karkha. 75 com
  • 76. Debugging Scripts % csh –n scriptname parse commands but do not execute them % csh –v scriptname Display each line of the script before execution % csh –x scriptname Displays each line of the script after variable substitutions and before execution can also be added to shebang line ! Karkha. 76 com
  • 77. Calling other scripts as subshell, via: csh scriptname scriptname subshell does not see current shell’s variables subshell sees current environment variables Karkha. 77 com

Notas del editor

  1. UNIX can be intimidating, and is not necessarily user-friendly. Your CS degree is built on knowing a variety of tools, and your knowledge of UNIX will prove very useful in your time here as well as your CS career. Most professors will require UNIX at some point. UNIX is a multi-user OS where users can share one machine&apos;s resources.
  2. Telnet is not supported. Run “ cshosts publinux, pub64, pub32” If you choose a machine with a long name, it will likely be less loaded than a machine with a name such as &apos;tig&apos;.
  3. In Windows, it starts at c: and then there&apos;s program files, then Microsoft office, then word, etc. Your home directory is yours to do everything you want. This is also how you access your homepage. Use the folder public_html. This shows up at http://www.cs.utexas.edu/~user
  4. Most of the time, you will get a warning message when something has failed. ***Talk about each column***
  5. Very few people who&apos;ve used UNIX for any amount of time end up using pico. emacs and vi are the two big editors, and both have a big learning curve. Typically, people choose one based on things like working with a lab partner who uses emacs, so they end up learning it too.
  6. NOTE: UNIX is Case Sensitive cd .. takes you up one directory cp and mv have two funtionalities: copy files copy to another directory ***When you overwrite a file, you will not get a message. A successful operation does not give feedback*** If you move a file to a dirname that hasn’t been created yet, the file will just be renamed.
  7. Space Bar, Page Down Up/Down Arrow, line-by-line
  8. X have to be running X Text files compress well. grep &apos;whatever&apos; to hang a process for termination. This is a sure bet that the process will hang since whatever doesn’t appear in any of my files AND there is no argument to complete the grep.
  9. Alpine, by default, comes with pico as it’s editor. &lt; &amp; &gt; go in and out of folders. ^J attaches a file
  10. Only print things for CS! Show how to get a webpage or pdf to print (entering command for printer) ***grep TAY from /etc/printcap***
  11. Karkha.com NIU - Department of Computer Science
  12. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  13. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  14. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  15. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  16. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  17. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  18. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  19. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  20. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  21. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  22. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  23. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  24. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  25. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  26. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  27. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  28. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  29. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  30. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  31. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  32. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  33. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  34. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  35. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  36. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  37. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  38. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  39. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  40. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005
  41. The C Shell Copyright Department of Computer Science, Northern Illinois University, 2005