jozef goetz, 2009 1 expanded by jozef goetz, 2008 copyright © 2005 pearson addison-wesley. all...
TRANSCRIPT
Jozef Goetz, 2009
1
expanded by Jozef Goetz, 2008
Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert Koretsky, Syed A. Sarwar
Jozef Goetz, 2009
2
Objectives
You may ignore last slides 63 – 69
To give an overview of the structure of a contemporary system
To describe briefly the structure of the LINUX/UNIX operating system
To detain some important system setups
Jozef Goetz, 2009
3
Objectives To introduce the LINUX/UNIX Text User Interface and
show the generic structure of LINUX/UNIX commands
To describe how to connect and log on to a computer running LINUX/UNIX operating system
To explain how to manage and maintain files and directories
To show where to get online help for LINUX/UNIX commands
To demonstrate the use of a beginner’s set of utility commands
To cover the basic commands and operators here and in coming chapters: alias, biff, cal, cat, cd, cp, exit, hostname, login, lp, lpr, ls, mesg, mkdir, more, mv, passwd, pg, pwd, rm, rmdir, talk, telnet, unalias, uname, whatis, whereis, who, whoami, write
Jozef Goetz, 2009
4
Computer System Hardware
Main/Primary Storage Central Processing Unit (CPU)
CPU clock: 3-4 G cycles per sec Disk Bus I/O Devices
Jozef Goetz, 2009
5
Computer System Hardware
Jozef Goetz, 2009
6Main/ Primary Storage
Purpose: To store executable programs or processes. Also called Volatile Storage place. Units: bit, byte, KB, MB, GB, TB
Jozef Goetz, 2009
7
Jozef Goetz, 2009
8Disk
A storage place that contains all the computer system’s programs and applications
A nonvolatile storage place Disks are read and written in terms of
sectors and blocks Speed of a disk drive is dictated by its
Latency Time the speed at which the drive can spin
Seek Time the speed at which the head can move
Jozef Goetz, 2009
9
I/O Devices
monitor plotter scanner CD-ROM DVD Flash drives –USB, SD etc.
Jozef Goetz, 2009
10Bus A set of parallel wires used to carry
information in the form of bits from one sub-system in a computer to another
System Bus data Bus, address bus, control bus
carry data, address of main memory, control info respectively
Loader Program reads the apps from the disk into memory
Fetch, decode and execute operations form a machine cycle
Jozef Goetz, 2009
11Execution of the application
1. When the user types at command line the name of the executable program name and hits the <Enter> to run the application
2. The loader program reads the app from the disk and loads to the main memory
3. And it then sets the internal state of the CPU so that it knows the location of the program’s 1st instruction, next see next slide
Jozef Goetz, 2009
12Central Processing Unit (CPU)
4. CPU executes the programs by fetching them from the RAM, one instruction at a time
RAM
Jozef Goetz, 2009
13Central Processing Unit (CPU)
Every CPU has its own language called its instruction set
A CPU is functionally divided into two parts Control Unit Execution Unit (or Arithmetic and Logic Unit
(ALU))
The storage locations of CPU are called Registers (# of registers a few to a few 100s with size 32 or 64 bits)
Jozef Goetz, 2009
14
UNIX Operating System
UNIX/LINUX is a multiuser, multiprocess operating system.
Multiuser – multiple users can use the computer system simultaneously.
Multiprocess – system can run several processes (executing programs) at the same time.
Jozef Goetz, 2009
15
UNIX Operating System
UNIX is mostly written in C language. Thus, it allows UNIX to be portable to many architectures.
And portability implies a use in variety of computer environments.
In fact, UNIX/LINUX runs on wider variety of computer then any other operating system.
Jozef Goetz, 2009
16
LINUX/UNIX Software Architecture From bottom:
Device Driver Layer Mouse, DVD, printer drivers,
etc interacts with various
hardware devices user cannot execute them
as commands The LINUX/UNIX Kernel
Process Management Create, suspend, terminate
processes Ps IPC (Interprocess
Communications) mechanisms
Pipe: related Ps, same cmpters
Named Pipe: unrelated Ps, same cmpters
BSD socket – Ps communicate in >1 network
File Management Create, remove files, Create, remove directories
Main Memory Management Allocate, dealocate RAM for
Ps Disk Management
Allocate, dealocate, free and used disk space, disk scheduling for file read, write etc.
Jozef Goetz, 2009
17Interprocess Communications IPC
Communication channels: Pipe
>= 2 related processes on the same machines
Named pipe (FIFO) >= 2 related or unrelated processes
on the same machines BSD socket
>= 2 processes in a network (or on the Internet)
Internet software such as Web browsers, ftp, telnet, e-mail are implemented using sockets.
Jozef Goetz, 2009
18
LINUX/UNIX Software Architecture The System Call
Interface Entry points to Kernel
System Call: The invocation of an operating
system routine to manipulate Ps, files and other system resources
Operating systems contain sets of routines for performing various low-level operations.
For example, all operating systems have a routine for creating a directory.
If you want to execute an operating system routine from a program, you must make a system call.
Language Libraries For C, C++, C#, Java,
FORTRAN etc.
LINUX/UNIX Shell: Starts when you logon and
interprets cmds Bourne Again, TC, Z, etc.
Jozef Goetz, 2009
19
LINUX/UNIX Software Architecture
Applications Compilers, word
processors, spreadsheets, ftp, telnet, Web browser etc.
can get the kernel code by using
a library calls a higher level
interface to the kernel than system calls
eventually use system calls
a system call
Jozef Goetz, 2009
20
AUI vs API
The command interpreter (e.g., a LINUX/UNIX shell) of an operating system and the applications layer comprise the application user’s interface (AUI).
The language libraries and the
system call interface comprise the application programmer’s interface (API).
See previous fig.
Jozef Goetz, 2009
21Process States
Possible process (P) states running (using the CPU at that
instant) blocked (waiting for external
event, CPU can be available) the process must execute a system
call: block or pause to get into blocked state
e.g. P reads a pipe or special file (e.g. a terminal) and there is no input available, P is automatically blocked
ready (no CPU available for it)
Transitions (T) between states shown
2 and 3 caused by the process scheduler (PS)
2 occurs when PS decides that the running P1 has run long enough, and it is time to let another P have CPU
3 occurs when all the other Ps have had their fair share and it is time for P1 to get CPU to run again
4 occurs when the external event for which process was waiting (such as the arrival some input) happens
Jozef Goetz, 2009
22
client–server software model
- the foundation for Internet applications
Jozef Goetz, 2009
23Logging On and Logging Off
Three basic ways of connecting to a LINUX/UNIX operating system:
1. Local Area Network Connection Intranet login: connect to a mainframe using terminal,
such as a VT-100 via a Sun workstation (which serves many terminals) Terminals are a dump graphical user interface to OS running on a
workstation A variation connect LINUX/UNIX workstation with a LINUX/UNIX
server
2. Internet Connection – federation of LANs and WANs windows telnet windows ftp PuTTY (the Telnet and SSH (secure shell) client itself) WinSCP WS_FTP_PRO or WS_FTP_PRO Explorer
3. Stand-alone connection A computer is not hooked up to a LAN, intranet, or the Internet
<Ctrl-D> - ending a session
Jozef Goetz, 2009
24
Connecting to UNIX PuTTY is a free implementation of Telnet
and SSH for Win32 and Unix platforms. More secure and easier to use then Telnet
Telnet is a terminal emulation program for the Internet. Not secure.
SSH (secure shell) is for UNIX/LINUX systems to provide authentication security for TCP/IP applications, such as FTP and Telnet. It can encrypt communications.
Jozef Goetz, 2009
25Connecting to UNIX via PuTTY
Jozef Goetz, 2009
26Connecting to UNIX via PuTTY
Jozef Goetz, 2009
27
Figure 3.5 Text-based login screen on a typical LINUX/UNIX computer
Jozef Goetz, 2009
28
3. Connecting via a Telnet Client on a Microsoft Windows Machine.
Jozef Goetz, 2009
29
Jozef Goetz, 2009
30
Entering Commands
UNIX/LINUX philosophy : it assumes that users know what are they doing.
UNIX/LINUX is a command based system. It is important to remember all commands and what they do.
Commands in UNIX/LINUX are programs.
UNIX/LINUX is case sensitive. Date and date is not the same.
Most UNIX/LINUX commands are in lowercase.
Jozef Goetz, 2009
31Structure of a UNIX Command
where:$ is the shell prompt,anything enclosed in [ ] is not always needed,command is the name of the valid UNIX command for
that shell in lowercase letters,[-option(s)] is one or more modifiers that change
the behavior of command,[option arg(s)] is one or more modifiers that change
the behavior of the -option(s),[command arg(s)] is one or more objects that are
affected by command, generally files and pathnames.
Space separates command, option, option argument, and command argument, but no space is necessary between multiple options or multiple option arguments. Also, a space is optional between the option and the option argument.
$ command [[-]option(s)] [option arg(s)] [command arg(s)]
Jozef Goetz, 2009
32Structure of a UNIX command
$ ls
Contains only the command ls$ ls –la
Contains the command ls and two options l and a
$ ls –la m*
Contains the command ls, two options l and a and command argument m*
$ lpr –Pps15 hw5.ps
Contains the command lpr, one option P, one option argument ps15 and one command arguments hw5.ps
$ command [[-]option(s)] [option arg(s)] [command arg(s)]
Jozef Goetz, 2009
33
The date Command
Use the UNIX date command to display the system date, which system administrator maintains
r – last file modification [cs253u@shell cs253u]$ date -r my Sat Jan 24 10:31:20 PST 2009
Jozef Goetz, 2009
34
The cal Command
Displays the calendar of the current month : cal
Displays the calendar of 2000 : cal 2000
Displays the calendar of Feb 1977 : cal 2 1977
Jozef Goetz, 2009
35The who and finger Commands
In a multiuser system, knowing who is logged into the system maybe helpful
Use the who command to determine who is using the system and their current location : who
[cs253u@shell cs253u]$ whogchang pts/2 Jan 28 17:05 (d-ecs-17x-205.fullerton.edu)gchang pts/3 Jan 26 09:56 (d-ecs-17x-205.fullerton.edu)nan pts/4 Jan 30 18:04 (d-ecs-18y-188.fullerton.edu)
Use the finger command to find out details about user : finger username
Jozef Goetz, 2009
36
The clear Command
Use clear command to clear your screen; it does not have options or arguments : clear
Jozef Goetz, 2009
37
Command Line History
Access the command history with up ↑ and down ↓ arrow keys.
Pressing the up arrow key ↑ once recalls the most recently used command.
Each time the up arrow key ↑ is pressed, an older command is recalled.
Each time the down arrow key ↓ is pressed, the next command in command line history is displayed.
Jozef Goetz, 2009
38LINUX/UNIX Command Usage
Viewing the Contents of Files cat, more, type, echo
create the Contents of Files:$ cat > myfile This is an example of how to use the cat command to add plain text to a file
<Ctrl-D>
$ more myfileThis is an example of how to use the cat command to add plain text to a file
$
cat –n file // put line # on the displayed lines
Jozef Goetz, 2009
39File Maintenance Commands Creating, Deleting and Managing Files
cp, mv, rm, ls
$ cp myfile myfile2 //copy$ mv myfile2 renamed_file // rename $ rm renamed_file //remove
// restore it$ cp myfile myfile2 //copy
$ lsmyfile myfile2 renamed_file
$ ls –al...details$ ls –F // slash after each directory demo literature/$ ls –-help
Usage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by default).Sort entries alphabetically if none of -cftuSUX nor --sort.
-a, --all => do not hide entries starting with .. .bash_history .bash_profile .emacs my .mysql_history.. .bash_logout .bashrc .gtkrc mydir .zshrc
-A, --almost-all => do not list implied . and ..
Jozef Goetz, 2009
40
File and Directory Structure
•Get Home Directory: cd ~•Print Working Directory: pwd
Jozef Goetz, 2009
41File Maintenance Commands
Creating, Deleting and Managing Directories mkdir, cd, pwd, rmdir$ mkdir first
$ cd first
$ pwd
/usr1.b/bobk/first
$ cd ..
$ pwd
/usr1.b/bobk
$ cp myfile myfile2
$ ls my*
myfile myfile2
$ rmdir first
rmdir: first: Directory not empty
$
Jozef Goetz, 2009
42
The man Command
The man command displays UNIX online manual, called the man pages, for command-line assistance : man who Press the space key to see more
manual pages, one screen at the time. Press Ctrl+b to go to the previous
screen. Press q to exit man program.
Jozef Goetz, 2009
43
Table 3.3 Sections of the LINUX/UNIX Manual
2-3 used by developers
Help on LINUX Command
Jozef Goetz, 2009
44Help on LINUX/UNIX Command
Obtaining Help with the man Command man [options][-s section] command-list
$ man ls
LS(1) FreeBSD General Commands Manual LS(1) // related to section 1
NAME
ls - list directory contents
SYNOPSIS
ls [-ABCFGHLPRTWZabcdfghiklmnopqrstuwx1] [file ...]
DESCRIPTION
For each operand that names a file of a type other than directory, ls displays
its name as well as any requested, associated information. For each operand
that names a file of type directory, ls displays the names of files contained
within that directory, as well as any requested, associated information.
If no operands are given, the contents of the current directory are displayed.
If more than one operand is given, nondirectory operands are displayed first;
directory and nondirectory operands are sorted separately and in lexicographical
order.
The following options are available:
Press <SPACE> to continue, or q to quit q$ man read
$ man passwd // password info
Jozef Goetz, 2009
45Figure 3.6 Manual Pages first screen display for man passwd command
Jozef Goetz, 2009
46Help on LINUX/UNIX Command
$ man ls
LS(1) FSF LS(1)
NAME ls - list directory contents
SYNOPSIS ls [OPTION]... [FILE]...
DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabeti¡ cally if none of -cftuSUX nor --sort.
-a, --all do not hide entries starting with .
-A, --almost-all do not list implied . and ..
$ ls –-helpUsage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by
default).Sort entries alphabetically if none of -cftuSUX nor --sort.
-a, --all do not hide entries starting with . -A, --almost-all do not list implied . and ..
$ man -s2 read // refer to section 2
$ man -k passwd // refers all the man sections that contain the keyword reference
chpasswd (8) - update password file in batchgpasswd (1) - administer the /etc/group filehtpasswd (1) - Create and update user
authentication filesldappasswd (1) - change the password of an LDAP
entrypam_localuser (8) - require users to be listed in
/etc/passwdpasswd (1) - update a user's authentication
tokens(s)passwd (5) - password filepg_passwd (1) - Manipulate the flat password filesaslpasswd (8) - set a user's sasl passwordsmbpasswd (5) - The Samba encrypted password
filesmbpasswd (8) - change a users SMB password
Jozef Goetz, 2009
47
Utility Commands
Examining System Setups whatis, whereis, whoami, which$ whoamibobk$ whereis mkdirmkdir: /usr/bin/mkdir$
[cs253u@shell cs253u]$ whatis whichwhich (1) - shows the full path of (shell) commands
[cs253u@shell cs253u]$ which dir/usr/bin/dir
Jozef Goetz, 2009
48
The whatis Command Sometimes man contains more
information then one wants to see. To display a brief summary of a
command use whatis command. The whatis shows only the name and
brief description that appears near the top of a command’s man page : whatis who
Use for help: cmd –-help man cmd whatis cmd
Jozef Goetz, 2009
49
Other Methods of Obtaining Help whatis
$ whatis login set setenvlogin(1) -sign on // 1 is the section #
set(1) -set runtime parameters for session
setenv(1) -change or add an environment variable
$[jgoetz jgoetz]$ whatis login
login (1) - sign on
[jgoetz jgoetz]$ whatis login set
login (1) - sign on
SET [set] (l) - Set run-time parameters for session
set (n) - Read and write variables
set [builtins2] (1) - bash built-in commands, see bash(1)
[jgoetz jgoetz]$ whatis setenv
setenv ( 3) - change or add an environment variable
LINUX/UNIX Command Usage
Jozef Goetz, 2009
50
The whereis Command
Locates binary, source and man page files for a command : whereis who
Jozef Goetz, 2009
51
The which Command
List which files are executed if the named commands are run as a command :
which who
Jozef Goetz, 2009
52
The uname Command
Determine the name of the operating system that your computer runs
[jgoetz jgoetz]$ unameLinux[jgoetz jgoetz]$ uname --helpUsage: uname [OPTION]...Print certain system information. With no OPTION, same as -s.
-a, --all print all information -m, --machine print the machine (hardware) type -n, --nodename print the machine's network node hostname -r, --release print the operating system release -s, --sysname print the operating system name -p, --processor print the host processor type -v print the operating system version --help display this help and exit --version output version information and exit
Jozef Goetz, 2009
53
The grep Command
grep - global regular expression print Searches a file for a pattern utility searches through file (o directories) to see if contains
a specified string of characters
-bash-2.05b$ grep 'initialization' sum# initialization of variables
-bash-2.05b$ who | grep 'cs253u2'cs253u2 pts/16 May 9 10:37 (10.67.28.199)
[jgoetz academia]$ cat jozef.html| grep head<head></head>
Jozef Goetz, 2009
54
Utility Commands Printing and General Utility
Commands lpr, cal
$ lpr -Pprintname file_name $ lpr –Pcs200 file_name // print your file in CS200 at the
printer designated // as cs200 - you can find this
format by entering // $help => look for “printing” $ cal // display calendar$ cal 11 2004
Jozef Goetz, 2009
55
Command Aliases The alias command can be used to create pseudonyms
(nicknames) for commands they can be placed in ~/.profile or ~/.login but typically in
a shell start files .bashrc (.cshrc for TC shell)
Syntax for the alias command is: alias [name [ = string ] …] // for Bourne, Korn, Bash shells
alias l=‘ls –la’ alias [name [ string ] ] // C shell
alias l ‘ls –la’ alias
list all aliases
remove it unalias ls // remove ls unalias –a // remove all
Jozef Goetz, 2009
56alias Command Examples
The \!* string is substituted by the actual parameter passed to the given command
For dir command, the shell actually executes the ls -la
Jozef Goetz, 2009
57
Table 3.4 Useful Commands for the Beginner (continued on next slide)
Jozef Goetz, 2009
58
Jozef Goetz, 2009
59
Jozef Goetz, 2009
60Correcting Mistakes
<Ctrl-D> to log off, at the shell prompt
for Bash shell
Jozef Goetz, 2009
61
Configuration Shells
~ is a shorthand for your home directory
[jgoetz jgoetz]$ whereis bash bash: /bin/bash /usr/man/man1/bash.1.gz[jgoetz jgoetz]$ whereis csh csh: /bin/csh /etc/csh.cshrc
[jgoetz jgoetz]$ whereis profileprofile: /etc/profile /etc/profile.d
Jozef Goetz, 2009
62
Logging Out of UNIX
Logging out ends your current process and indicates to UNIX that you are finished.
Logging out depends on the shell. In C shell, type logout.
For Bourne, Korn or Bash shells type exit or press ctrl+d.
Jozef Goetz, 2009
63pine – E-mail System on CSE
Allows to send and receive e-mail. The most extensive and friendly e-mail
program for UNIX. To start pine:
Type pine and press <Enter>, the pine Main Menu will appear.
To exit pine: At almost any place in pine press q – for quit.
You are asked: really quit the pine. Press y – for yes and press <Enter>.
Up ↑ and down ↓ arrow keys help navigate the cursor.
Jozef Goetz, 2009
64
pine - Main MenuL – go the folder list
Jozef Goetz, 2009
65pine – Composing a Message
• To compose a message press c .
• The ^ character indicates the control key. •Ctrl key must be pressed down while the letter for each command is pressed too.
Jozef Goetz, 2009
66
Test Message to Yourself
1. Press c to compose.2. In the To field type email address and
press <Enter>.3. In the Cc field press <Enter>.4. In the Attachment field press <Enter>.5. In the Subject field type Test and press
<Enter>.6. Below the Message Test line type This is
a test.7. To send a message press ^x ( ctrl + x ) .
You are asked: Send a message?8. Press y or press <Enter>.
Jozef Goetz, 2009
67
Reply / Forward Message
To reply To replay to a selected or a currently viewed
message press r. You are asked whether you want to include
the original message in your replay. Also, if the original message was sent to more
then one person, you are asked if you want to replay to all recipients.
To forward To forward a selected or a currently viewed
message press f. Enter the email address and send as usual.
Jozef Goetz, 2009
68
Summary
In UNIX?LINUX, you communicate with the operating system programs through an interpreter called the shell, which interprets the command entered from keyboard.
Jozef Goetz, 2009
69
Metric Units
The metric prefixes