operating systems design n.
Skip this Video
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 39


  • Uploaded on

OPERATING SYSTEMS DESIGN. UNIX BASICS & SHELL SCRIPTING. What Is UNIX?. UNIX is an operating system (OS) Multiuser – computer system used by more than one person at the same time Multithreaded – multiple simultaneous use of the same program

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'OPERATING SYSTEMS DESIGN' - lowri

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
operating systems design





what is unix
What Is UNIX?
  • UNIX is an operating system (OS)
    • Multiuser – computer system used by more than one person at the same time
    • Multithreaded – multiple simultaneous use of the same program
    • Multitasking – handles more than one job (task) per person at the same time
  • The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
  • As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.
filesystem hierarchy standard
Filesystem Hierarchy Standard
  • Outlines standard locations for files and directories
  • Gives software developers a consistent context regardless of the distribution
  • Helps users of one system work on another
some useful commands
Some useful commands
  • cd - change directories (built into shell)
  • wc - word, line, character, and byte count
  • echo - echo characters back (print)
  • passwd - change password
  • sort - sort lines of a text file
  • ls - lists the contents of your current working directory
some useful commands1
Some useful commands
  • cp - copy a file(s)
  • ps - status of processes (what’s running)
  • pwd - Prints the current directory.
  • kill [-sig] %job
    • Send signal sig to the specified job. sig can be either numeric or symbolic. kill -l lists all available signals. By default, sig is SIGTERM (15).
  • read name - Reads one line from standard input and assigns it to the variable name.
some useful commands2
Some useful commands
  • grep - It searches files for specified words or patterns.
    • $ grep -i science science.txt
  • wc - does a word count
  • Last but one of most important command is MAN
finding files
Finding files
  • locate command
    • Fastest method to search for files
    • A shortcut to the slocate (or secure locate) command
  • find command
    • Used to find files using various criteria
    • Searches the directory tree recursively, starting from a certain directory, for files that meet criteria
which command and path variable
which command and PATH variable
  • which command
    • Used to locate files within directories listed in the PATH variable
  • PATH variable
    • Stores list of directories searched when commands are executed without an absolute or relative pathname
  • A shell is a command interpreter.
  • The shell acts as an interface between the user and the kernel.
  • You can put commands in a file and execute them all at once.
  • The script itself is just a series of commands.
  • Comments begin with a hash (#) and continue to the end of the line (the first line is special)
bin sh
  • The first line of any script must begin with #!, followed by the name of the interpreter.
  • When Unix tries to execute the script, it sees the first two characters (#!) and knows that it is a script.
  • It then reads the rest of the line to find out which program is to execute the script.
running a script
Running a script
  • chmod +x {script_name}
  • ./{script_name}
  • Variables do not need to be declared.
  • There is only one type of variable
  • VAR=valueSet value to variable
  • $VAR or ${VAR} Use the value of the variable
  • COLOR=yellow

echo This looks $COLORish

echo This seems ${COLOR}ish

special variables
Special variables
  • Command-line arguments
  • $1 refers to the first command-line argument (after the name of the script), $2 refers to the second one, and so forth, up to $9.
  • If you have more than nine command-line arguments, you can use the shift command: this discards the first command-line argument, and bumps the remaining ones up by one position: $2 becomes $1, $8 becomes $7, and so forth.
special variables contd
Special variables (contd.)
  • The variable $0 (zero) contains the name of the script
  • $* (star) and $@ (at) Each of these expands to a string containing all of the command-line arguments, as if you had used $1 $2 $3...
  • inside “double quotes”: $* behaves in the normal way, whereas $@ creates a separate double-quoted string
  • $# contains the number of command-line arguments that were given.
other special variables
Other special variables
  • $? gives the exit status of the last command that was executed.
  • $- lists all of the options with which sh was invoked.
  • $$ holds the PID of the current process.
  • $! holds the PID of the last command that was executed in the background
  • $IFS (Input Field Separator) determines how sh splits strings into words.
  • Single quotes : anything inside them (except a single quote) is quoted.
  • A backslash inside single quotes also loses its special meaning
  • Double quotes : preserve spaces and most special characters. However, variables and backquoted expressions are expanded and replaced with their value.
  • Backquotes : the expression is evaluated as a command
  • A backslash (“\'') removes any special meaning from the character that follows.
  • The backslash is itself special, so to escape it, just double it: \\.
flow control
Flow control
  • #!/bin/sh


if [ $myname = root ]; then

echo "Welcome to FooSoft 3.0"


echo "You must be root to run this script"

exit 1


while for
While & For
  • while condition; do commandsdone
  • for i in foo bar baz "do be do"; do

echo "$i"


i o redirection
I/O redirection
  • “< filename” Connect standard input to the file filename. This allows you to have a command read from the file.
  • “> filename” Connect standard output to the file filename. This allows you to save the output of a command to a file. If the file does not exist, it is created. If it does exist, it is emptied before anything happens.
i o redirection contd
I/O redirection (contd.)
  • “>> filename”Connects standard output to the file filename. Unlike >, however, the output of the command is appended to filename.
  • “command1 | command2”  Creates a pipeline: the standard output of command1 is connected to the standard input of command2.
  • When a group of commands occurs several times in a script, it is useful to define a function.
  • name () { commands}
useful utilities
Useful utilities
  • basename : basename pathname prints the last component of pathname.
    • basename /foo/bar/baz prints baz
  • dirname : dirname pathname prints all but the last component of pathname, that is the directory part: pathname
    • dirname /foo/bar/baz prints /foo/bar
  • /bin/[ is another name for /bin/test.
  • It evaluates its arguments as a boolean expression, and exits with an exit code of 0 if it is true, or 1 if it is false
[ (contd.)
  • -e filename
    • True if filename exists.
  • -d filename
    • True if filename exists and is a directory.
  • -r filename
    • True if filename exists and is readable.
  • s1 = s2
    • True if the strings s1 and s2 are identical.
  • s1 != s2
    • True if the strings s1 and s2 are not identical.
  • n1 -eq n2
    • True if the numbers n1 and n2 are equal.
  • n1 -ne n2
    • True if the numbers n1 and n2 are not equal.
  • expr1 -a expr2
    • True if both expressions, expr1 and expr2 are true.
sed strem editor
SED (Strem EDitor)

What is Sed ?

  • A “non-interactive” text editor that is called from the unix command line.
  • Input text flows through the program, is modified, and is directed to standard output.
sed contd
SED (contd.)
  • sed -e '/^#/d’
  • sed -e 's/foo/bar/g'
regular expressions
Sed uses regular expressions to match patterns in the input text, and then

perform operations on those patterns.

^ matches the beginning of the line

$ matches the end of the line

. Matches any single character

\ Escapes any metacharacter that follows, including itself.

(character)* Match arbitrarily many occurences of (character)

(character)? Match 0 or 1 instance of (character)

(character)+ Match 1 or more instances of (character)

[abcdef] Match any character enclosed in [ ] (in this instance, a b c d e or f)

[^abcdef] Match any character NOT enclosed in [ ]

(character)\{m,n\} Match m-n repetitions of (character)

(character)\{m,\} Match m or more repetitions of (character)

(character)\{,n\} Match n or less (possibly 0) repetitions of (character)

(character)\{n\} Match exactly n repetitions of (character)

\{n,m\} range of occurrences, n and m are integers

\(expression\) Group operator.

expression1|expression2 Matches expression1 or expression 2.

() groups regular expressions

Regular Expressions
regular expressions character classes
Regular Expressions (character classes)

The following character classes are short-hand for matching special characters.

[:alnum:] Printable characters (includes white space)

[:alpha:] Alphabetic characters

[:blank:] Space and tab characters

[:cntrl:] Control characters

[:digit:] Numeric characters

[:graph:] Printable and visible (non-space) characters

[:lower:] Lowercase characters

[:print:] Alphanumeric characters

[:punct:] Punctuation characters

[:space:] Whitespace characters

[:upper:] Uppercase characters

[:xdigit:] Hexadecimal digits

  • Awk (and its derivatives, nawk and gawk) is a full-fledged scripting language.
  • Inside sh scripts, it is generally used for its ability to split input lines into fields and print one or more fields.
awk contd1
AWK (contd.)
  • awk -F : '{print $1, $3 }' /etc/passwd
  • The -F : option says that the input records are separated by colons. By default, awk uses whitespace as the field separator.
  • Sum up column 2 and print the total

{total += $2} END { print total}

awk example
AWK Example
  • Print fields in reverse order one per line


for (i=NF; i>=1; i--)

print $i;


end of lab 1