UNIX User Interface - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

UNIX User Interface

Description:

Regarding SCO's positioning on UNIX, The Open Group would like to make it clear ... PS4. TMOUT. VISUAL. Types of bash Shells. Login shell. Default shell for user ... – PowerPoint PPT presentation

Number of Views:212
Avg rating:3.0/5.0
Slides: 61
Provided by: jbm
Category:
Tags: unix | interface | ps4 | user

less

Transcript and Presenter's Notes

Title: UNIX User Interface


1
UNIX User Interface
  • Davis Rajkumar (6th), Chp. 9
  • Solaris, bash shell
  • man pages

2
Overview
  • UNIX and Linux
  • User interfaces
  • Solaris terminal sessions
  • Command line instructions
  • File system
  • Working with files
  • Pipes, filters, and redirection
  • Scripts

3
UNIX and Linux
  • UNIX
  • Developed by Thompson and Ritchie (1969)
  • Important contributions to modern OS
  • Developed by and for programmers
  • Linux
  • Kernel developed by Torvald (1994)
  • Uses GNU utilities to create complete OS

4
Unix Development
Source Twork, et. al.
5
Who Owns UNIX?
  • Regarding SCO's positioning on UNIX, The Open
    Group would like to make it clear that SCO holds
    the rights ONLY to the operating system source
    code (originally licensed by ATT) and related
    intellectual property and DOES NOT OWN the UNIX
    trademark itself or the definition (the Single
    UNIX Specification) of what the UNIX system is.
    Reference to the SCO web site shows that they
    own certain intellectual property and that they
    correctly attribute the trademark to The Open
    Group. SCO has never owned "UNIX".  SCO is
    licensed to use the registered trademark UNIX "on
    and in connection" with their products that have
    been certified by The Open Group, as are all
    other licensees. These are the ONLY
    circumstances in which a licensee may use the
    trademark UNIX on and in connection with it's
    products. Statements that SCO "owns the UNIX
    operating system", has "licensed UNIX to XYZ" are
    clearly inaccurate and misleading .Source Open
    Group, Backgrounder on the UNIX System and SCO
    / IBM legal action, http//www.unix-systems.org/b
    ackgrounder.html

6
Unix Features and Capabilities
  • Multitasking concurrent execution of several
    processes
  • Multiple users more than one user using system
    at one time
  • Portable
  • Kernel written in C, a high-level language
  • Wide number of vendor platforms implemented by
    recompiling source
  • UNIX tools
  • Integrated utilities
  • Large number of simple tools can be added as
    needed
  • Use of pipes and filters to undertake complex
    tasks through simple tools
  • System services are provided through daemon
    processes
  • Built-in networking TCP/IP and e-mail are
    standard
  • Customizable open source
  • Default user interface is character-based
  • Use of files as handles to reference devices and
    other objects
  • Programming interface wide range of languages
    supported
  • Scalable multiprocessors and clustering
    supported

Sources Twork et. al. Echert and Schitka, and
Lucent Technologies
7
User Interfaces
  • Applications use POSIX Portable Operating
    System Interface for Unix
  • People use
  • Applications
  • Shells
  • GUI
  • CDE/KDE
  • Knome/Gnome

Applicationprogram
User
Operating system layer
Hardware layer
8
Purpose of Shells
  • Interface between user and kernel
  • User may be person or program
  • Provide access to system calls

9
Shell Characteristics
  • Character user interface (CUI) or graphical user
    interface (GUI)
  • CUI effective tool in Unix
  • Useful for programming repetitive tasks
  • Edit configuration files (all text files)
  • Easier to write shell script than develop Windows
    application
  • Files /etc/profile /etc/environment .profile
    .env rc /bin/sh

10
Common Shells
  • Bourne shell (/usr/bin/sh) standard job control
    shell Original UNIX shell used for writing
    scripts Provides variable, command and filename
    substitution
  • Bourne Again SHell (/usr/bin/bash) sh-compatible
    and incorporates features of Korn and C shells
    open source (GNU)
  • C shell (/usr/bin/csh) uses C syntax and
    provides feature not found in Bourne shell
    Command aliasing History substitution Job
    control
  • Korn Shell (/usr/bin/ksh) Provides more
    environmental control then Bourne shell
  • Enhanced Berkley C shell (/usr/bin/tcsh) C shell
    with file name completion and command line editing

11
Other Shells of Interest
  • Remote shell (/usr/bin/rsh) connects to
    specified host and executes specified command
  • Job control shell (/usr/bin/jsh) same as sh
  • Z shell (/usr/bin/zsh) Includes many
    enhancements to Korn shell
  • Command line editing
  • Built-in spelling correction
  • Programmable command completion
  • History

12
Solaris Terminal Sessions
  • Login
  • SSH Client
  • Login
  • Turn-off menu
  • Prompt usually indicates shell
  • for Bourne (sh), Bourne Again (bash), Korn
    (ksh) shells
  • for C shell (csh), Z shell (zsh)
  • gt for extended C shell (tcsh)

13
Command Line Instructions
  • Syntaxcommand -options arguments
  • Command
  • String that identifies command
  • See Appendix C
  • Options
  • Not all commands have options
  • Not required
  • Proceeded by dash
  • Arguments
  • Files, directories, or devices used with command
  • Separated by spaces

14
Useful Commands
  • Display content of a file cat filename
  • Change directory cd dirpath
  • Change permissions on file or directory chmod
    mode objName
  • Clear display clear
  • Copy file cp source destination
  • Append text to a file echo string gtgt filename
  • Search directory for file find path string
  • Search text for string text grep i string
  • View screen at a time less filename OR command
    less
  • View content of a directory ls OR ls dirPath
  • Get help on a command man command
  • Create a directory mkdir dirName
  • Change name of a file mv oldName newName
  • Move a file mv fileName dest
  • Display present working directory pwd
  • Delete a file rm filename
  • Delete a directory rmdir dirName

15
Commands to Lookup
  • alias
  • awk
  • banner
  • batch
  • chown
  • cut
  • date
  • groups
  • groupadd
  • kill
  • ls
  • netstat
  • paste
  • ps
  • passwd
  • read
  • script
  • sh
  • spell
  • sort
  • su
  • talk
  • tail
  • time
  • touch
  • useradd
  • vi

16
bash
  • Bourne shell (sh) compatible command language
    interpreter
  • Executes commands for standard input or files
  • Incorporates features of Korn and C shells
  • Conformant implementation of IEEE POSIX Shell and
    Tools specification (IEEE 1003.2)

17
POSIX Standard
  • Portable Operating Systems Interface
  • Standards defines a standard operating system
    interface and environment
  • Command interpreter (or "shell")
  • Common utility programs to support applications
    portability at source code level

Source http//www.unix.org/single_unix_specificat
ion/
18
POSIX Basic Regular Expressions
  • Regular expressions used for text processing
  • Includes decoding shell commands
  • Zero or more characters followed by ltnewlinegt
  • Ordinary characters any character in supported
    character set, except for special characters
  • Special characters have special properties in
    certain context
  • Matching is by bit pattern used for encoding
    character, not on graphic representation of
    character.

19
Identifying Current Environment
  • Default shell echo SHELL
  • Current search path echo PATH
  • What's your login info who am i
  • More info about user finger loginID
  • Much more info about env set OR env
  • Who's logged in who

20
POSIX Environment Variables
21
Safe Environment Variables
  • CDPATH
  • COLUMNS
  • EDITOR
  • ENV
  • HISTFILE
  • HISTFILESIZE
  • HISTSIZE
  • HOSTFILE
  • IGNOREEOF
  • LINES
  • MAIL
  • MAILCHECK
  • MAIL_WARNING
  • noclobber
  • PATH
  • PROMPT_COMMAND
  • PS1 prompt
  • PS2
  • PS3
  • PS4
  • TMOUT
  • VISUAL

22
Types of bash Shells
  • Login shell
  • Default shell for user
  • Or shell started with --login option
  • Interactive
  • Standard input and output connected to terminal
  • Or shell started with i option
  • Non-interactive
  • Shell invoked with name sh
  • Does not read startup files

23
bash Interactive Invocation
  • Login shell executes following in order unless
    --noprofile used at shell's startup
  • /etc/profile
  • /.bash_profile
  • /.bash_login
  • /.profile
  • Not login shell executes /.bashrc
  • If /.bashrc exits
  • If not inhibited by option norc
  • Option --rcfile filename forces file named to
    execute as bashrc file and /.bashrc will not run

24
Configuring bash
  • Edit /.bashrc
  • Some syntax
  • Comment symbol
  • Continuation symbol \ltnewlinegtltnewlinegt
    represents pressing Enter key
  • Using environment variable value ENV_VAR
  • Setting environment variables ENV_VARvalueexpor
    t ENV_VAR1, .., ENV_VARn
  • Creating aliases alias newCmd'command'

25
Example .bashrc File
  • This is a comment in this example
  • bash run control file.
  • Adding to the search path
  • PATHPATH/usr/sbin
  • Change prompt
  • PS1"\u_at_\host\w\\"
  • Make environment changes work
  • export PATH, PS1
  • Create aliases
  • alias ll'ls al'
  • alias renamemv

26
Special Symbols for bash Prompt
  • \u Show current loginID
  • \w Show current directory with path
  • \W Show current directory without path
  • \t Show time
  • \d Show date
  • \n Force newline
  • \h Show short hostname
  • \H Show long hostname
  • \s Show shell's name
  • \v Show shell's version
  • \! Show command history number

27
Example PROMPT_COMMAND
  • meant to be sourced from your bash environment
  • this will display a colored error code if the
    previous function
  • returned an error, or just the regular prompt
    otherwise.
  • JPM ltjpmartin_at_cs.utexas.edugt
  • showIfError ()
  • AUX?
  • if AUX -gt 0 then PREFIX"\\033133m\
    AUX " else PREFIX"" fi
  • PS1"PREFIX\\033132m\\w\\03300m\\
    "
  • PROMPT_COMMANDshowIfError

28
Sending Messages
  • mesg -y
  • Allows messages
  • If mesgn, no messages
  • write DestLoginID
  • DestLoginID is danaID of destination
  • Type message and press Enter key
  • To terminate use Ctrl-d
  • Ctrl-d is End Of Transmission ltEOTgt

29
Lets Try Some Commands
  • Using bash shell
  • Commands
  • date
  • who
  • who am i
  • man
  • apropos
  • ps
  • Variables
  • env
  • echo varName

30
Shell Recap
  • Shell interpret commands and control jobs
  • Common shells sh, bash, csh, ksh, tcsh
  • ls /bin lists general commands
  • ls /usr/sbin lists system admin commands
  • man cmdName tells about command named
  • Shells are customizable
  • bash is sh-compatible and POSIX compliant
  • She sells seashells by the seashore

31
File System
  • Hierarchical file systems
  • Tree structure of root, directories, and
    subdirectories
  • Root (/) primary directory
  • Directory can contain files, links, or other
    directories
  • File names
  • Case sensitive
  • 1 to 255 letter, digits, . , _
  • Dont use spaces or /
  • Extension is optional

32
File Formats Supported by Solaris
  • cachefs CacheFS cached file system
  • hsfs High Sierra file system
  • nfs Network File System (NFS)
  • pcfs MS-DOS file system floppy diskettes
  • tmpfs file system that uses memory
  • ufs standard UNIX File System (UFS)

33
Paths
  • Path List of all subdirectories (and other
    elements) one must navigate to get to specific
    file (device or directory)
  • Absolute path begins at root (/)
  • Relative path begins at parent (..) or current
    (.) directory
  • Search path
  • PATH in environment
  • Used to locate files, devices, or directories

34
Working with Files
  • pwd show present working directory
  • ls list content of directory
  • mkdir make directory
  • rmdir remove directory
  • cd change directory
  • cat display content of file
  • less display content of file one screen at a
    time
  • cp copy one or more files
  • rm remove one or more files
  • mv move or rename one or more files
  • find find a file or string in a file
  • touch create or change modified date on file

35
Redirection
  • Redirection changes source of input or
    destination of output
  • echo This is a junk file created by USER gt
    junk.del

36
Filters
  • Modifies data in some way
  • sort sorts lines of input
  • b ignore blanks
  • d dictionary sort
  • n numeric sort
  • r reverse order
  • grep searches based on string pattern
  • i ignore case
  • n display line number

37
Pipe
  • Pipe connects two commands together
  • Examples
  • cat file1 sort
  • ps -ef grep -i USER
  • Doing complex tasks with simple commandscombine
    commands
  • cat file1 sort -d grep -in m gt file2

38
File Permissions
  • Used to grant or deny access
  • By owner, group, other
  • read, write, execute
  • rwxr--r--
  • To check current permissions, use ls l
  • To change permissions, use chmod nnn target
  • Default file permissions set by umask
  • Subtract from permission
  • 000 777-000777rwxrwxrwx
  • 333 777-333444r--r--r--
  • 037 777-037740rwxr-----
  • 022 is typical rwxr-xr-x

39
Scripts
  • Line commands and shell control instructions
    written in text file
  • Used for repetitive tasks
  • Bourne scripts used in system administration
  • REMINDER Examples of commands are for bash shell.

40
Use of Scripts
  • Simplify repetitious common tasks
  • Finding and copying all files related to a
    project
  • Spell checking and renaming spellchecked
    documents in a project
  • Automate administrative tasks
  • Generating user accounts
  • Gather information about users by group
  • Tracing disk space use by group and user
  • Greeting users with account related information
    when they login
  • Check logs for specific conditions
  • Enable replication and debugging of complex tasks
  • Manage job composed of related applications whose
    execution depends on exit state of preceding
    applications
  • Creating periodical reports

41
Creating Shell Script
  • Use text editor to create and edit script file
  • Start script with ! /bin/sh
  • Add shell script code
  • Save and close file
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_1 This is my first shell script
  • echo "Hello, world."
  • echo "\tThe current date is date D."
  • echo "\tThe current time is date R."
  • echo "\tThe following users are logged-in"
  • who
  • echo "\nYour account information"
  • finger USER
  • end script

42
Making Script Executable
  • Make sure the script starts with ! /bin/sh
  • Can use "head" command to just view first two
    lines
  • head -2 fileName
  • Make sure the user has execution rights
  • Use ls l filename to view current permissions
  • Use chmod to make sure user has execution
    permission
  • chmod ux filename
  • Make sure that the current working directory is
    in PATH
  • cd to directory containing script
  • pwd echo PATH
  • If pwd is not add to path
  • PATHPATHpwd
  • Test configuration by typing scripts filename at
    prompt

43
Quicker Script Development
  • Use vi to empty .bash_history
  • In the bash shell, perform task to be performed
    by script
  • When you have completed the task, copy the
    history to a script file
  • history gt scriptName
  • OR
  • cp /.bash_history scriptName
  • Edit the script file to remove line numbers,
    format output, add control structures, and input
    code

44
Embedding Commands
  • Embedded command is a command within a command,
    such as
  • echo "Date date D"
  • Use grave,, to delimit embedded command
  • To show last file accessed in current directory,
    embed ls command in echo command
  • echo "Last file used in pwd ls -1Ft head
    -1"
  • To show a list of directories and files in a
    user's home directory, again embed an ls command
    in an echo command
  • echo "Home directory USER\nls -R HOME"

45
Script Control Structures
  • Control structures allow determining path of
    execution during execution
  • Similar to other programming languages, scripts
    have control structures
  • Sequential statements block of commands executed
    in order listed
  • Iteration loops that repeat block of commands
  • Selection if then else fi

46
Iteration
  • Bourne shell scripts may use iteration and
    selection
  • Iteration control structure is "for i in ... do
    ... done" loop
  • Example iteration, copying all of the text files
    you have created to .bak before revising them
  • Create some text files touch shells.txt
    editing.txt scripts.txt
  • Create text file using vi example script follows

47
Iteration Example 1
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_2 Script to backup text files
  • for i in ls -1 .txt
  • do
  • cp i i.bak
  • echo "i copied"
  • done
  • end script

48
Iteration Example 2
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_3 This script deletes all .bak files
  • for i in ls -1 .bak
  • do
  • rm i
  • echo "i deleted."
  • done
  • end script

49
Notes about Iteration
  • Now you have one script to create .bak files and
    one to delete them
  • Indention in script uses tab not spaces
  • "i" is a variable could be "j" or "text_file" or
    some other identifier you dream-up

50
Selection
  • Selection is "if ... then ... else ... fi"
  • Logical operators
  • a eq b a equals b
  • a ne b a not equal b
  • a gt b a greater than b
  • a ge b a at least b
  • a lt b a less than b
  • a le b a at most b
  • ! a not a
  • File permissions returned by "test"
  • -a file exists
  • -b special block file
  • -c special character file
  • -d directory
  • -f normal file
  • -h symbolic link
  • -p named pipe
  • -r readable
  • -s nonzero size
  • -w writeable
  • -x executable

51
Example Selection Script
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_4 Copy all executable files to
    /scripts
  • for my_file in ls R HOME
  • do
  • if test d my_file
  • then
  • echo "Checking my_file for executable
    files."
  • else
  • if test x my_file
  • then
  • cp my_file HOME/scripts
  • echo "my_file copied to HOME/scripts."
  • fi
  • fi
  • done
  • end script

52
Input for Scripts
  • Two type of input considered here
  • Input as arguments from command line invoking
    script
  • Input from standard input during execution
  • Input from command line arguments
  • Arguments are positional, so that first is 1,
    second 2, and so on
  • Arguments assumed to be text unless
    square-bracket used in comparison
  • Input from standard input
  • Use "read" statement
  • May use iteration, such as "while" loop

53
Command Line Argument Script
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_5 Compare two numbers and determine
  • which is larger
  • if 1 gt 2
  • then
  • echo "1 is more than 2"
  • else
  • echo "1 is at most 2"
  • fi
  • end script

54
Example Standard Input Script
  • ! /bin/sh
  • Programmer J.Maris
  • Date created 11-Feb-2004
  • SCRIPT_6 Script to accumulate sum of values
    entered by user
  • user_done"n"
  • total0
  • while user_done "n"
  • do
  • echo "Enter a number "
  • read num
  • totalexpr total num
  • echo "\tCurrent total total"
  • echo ""
  • echo "Are you done? (y or n) "
  • read user_done
  • echo "Status user_done"
  • done
  • echo "Final total total"
  • echo ""

55
Debugging Scripts
  • An option with the sh command is x, which cause
    script commands to be echoed
  • To break out of an indeterminate loop, use Ctrl-c
  • Use echo statements in script to show variables'
    content

56
List of Codes for Pretty Echo
  • Following codes are used with echo command in
    double-quotes. Following are two examples. The
    first shows the echo command used at the prompt.
    The second shows the echo command used in script.
  • At prompt echo e "User\tUSER"
  • In script echo "Title\n"
  • Codes
  • \b move back one space overwrites previous
    character
  • \c force following command to appear on current
    line suppresses newline
  • \f force following command to appear on
    following line at specified horizontal
    location
  • \n newline
  • \t indent one tab

57
List of Codes for Date Formats
  • The following codes can be used in conjunction
    with the date command to format the date, such as
    scripting the date to display in d-mmm-yyyy
    format
  • echo "\tDate\tdate d\c" echo "-date
    b\c" echo "-date Y"
  • Codes
  • d numeric day of month
  • y two-digit year
  • Y four-digit year
  • m numeric month
  • b three letter month
  • B full month name
  • a abbreviated day of week
  • A full day of week
  • R time in 24-hour format
  • D date in month/day/year format

58
Script Recap
  • Scripts are files containing shell commands and
    control statements
  • Bourne scripts support selection, iteration,
    variables, and input
  • To create a script, put commands in a file
  • To make a script executable, change the
    permissions to include ur, and make sure the
    script is in your PATH

59
Summary
  • Kinds of Unix user interfaces
  • GUIs cde/kde, knome/gnome
  • Shells sh, bash, csh, zsh, ksh, tcsh
  • Logging in
  • Unix commands for command line
  • command -options arguments
  • Hundreds available
  • File system
  • Hierarchical
  • Paths absolute, relative, search
  • Redirection, filters, and pipes used to perform
    complex tasks using simple commands
  • Script text file containing shell commands and
    control structures

60
Questions?
61
References
  • Larry Twork, Larry Mead, Bill Howison, JD Hicks,
    Lew Brodnax, Jim McMicking, Raju Sakthivel, David
    Holder, Jon Collins, Bill Loeffler, Unix
    Applications Migration Guide, Microsoft
    Corporation, http//msdn.microsoft.com/library/def
    ault.asp?url/library/en-us/dnucmg/html/UCMGch02.a
    sp, October 2002, Chapter 2.
  • Lucent Technologies, An Overview of the UNIX
    Operating System, http//www.bell-labs.com/histor
    y/unix/tutorial.html, 2002. UNIX is a
    registered trademark of The Open Group.
  • man pages on gold and jan
  • Ray and Ray. VISUAL QUICKSTART GUIDE FOR UNIX.
    Peachpit Press, 1998.
  • Watters. COMPLETE REFERENCE FOR SOLARIS 9.
Write a Comment
User Comments (0)
About PowerShow.com