Professional Documents
Culture Documents
Lecture 1
Introduction
Basics
Computer
Collection of components that can perform arithmetic and logical calculations at incredible speed
Hardware
Actual circuits and associated machinery that is visible as a computer CPU, disk, tape, keyboard, monitor, etc.
Software
Sequence of instructions/commands to make the computer perform a desired task
Computer Systems
Organization
Hardware
Memory
RAM (Random-Access Memory) Holds the machine code and data ( forgets later ) ROM (Read-Only Memory) Contents are remembered and may not be changed
4
Hardware
Disk
Secondary memory (also Tapes, Floppy disks, ...) Holds large amounts of data and code Remembered after computer is turned off
I/O Devices
Input devices Monitor, Keyboard, Mouse, Scanner, etc. Output devices Monitor, Printer, Speaker, etc.
Software
File
A collection of instruction/data stored on disk
Program
A collection of bytes representing code and data that are stored in a file Most of the programs we use (or write) are application programs
Process
When a program starts, it is loaded from disk to RAM Once it is loaded into memory and is executed, it is called process
6
Operating System
Special software
An interface between hardware and application program Coordinates most of the computer system components Manages processes and resources Without it, the computer cannot function properly
Examples
Windows XP, UNIX, VMS, Mac OS X, ...
UNIX
Written in C language
Portable
UNIX
UNIX
10
Logging in/out
Logging in
Type in your username and password The system sets up a working environment according to some hidden files (e.g., .cshrc, .login, .profile) Unix is case sensitive, so be careful with the case you type Connecting from other machines Use telnet (or rlogin, ssh) e.g., telnet admiral.umsl.edu e.g., rlogin admiral.umsl.edu l apujols
11
Logging in/out
Logging out
Use logout or exit command ^D (Ctrl-D) also works It terminates current shell Is also means end of input or end of file $ cat > alice.txt And I fall into them, Like Alice fell into Wonderland. ^D $
12
Shell
What is shell?
An interface program between user and UNIX Provides environment to work in Interprets commands and executes them Shows a prompt (%, $, ...) to receive commands $ (type your command here) % (type your command here)
13
Shell
Popular shells
Author Stephen Bourne Bill Joy David Korn Ken Greer Brian Fox
Prompt $ % $ % $
14
Shell
15
Utilities
Form
% utility [option(s)] <parameter(s)>
Mostly in lowercase letters Options are prefixed by a dash (-r, -f, ...)
16
Utilities
Examples
date utility (displays the current date and time) % date Thu Jan %
17
pwd(1)
...
18
File system
% ls -al drwxr-xr-x drwx------rwxr-xr-x -rw-r--r-2 4 1 1 apujols apujols apujols apujols 100 100 100 100 512 512 8224 454 Jan Jan Jan Jan 4 2 4 4 22:29 17:59 21:29 21:30 ./ ../ a.out* cube.c
19
Pathname
Absolute pathname
20
Pathname
Relative pathname
./myFile.c ../myFile.c ../../bin/myFile.c HW1/myFile.c . indicates current directory .. indicates parent directory ~ indicates your home directory ~apujols indicates home directory of user apujols
21
I/O channels
Standard channels
stdin Standard input stdout Standard output stderr Standard error (where program writes error messages)
22
I/O channels
Standard channels
By default, all of these channels are the terminal can be redirected by using > or < symbols % myprogram < input.data % myprogram > output.data
23
Basic utilities
Basic utilities
25
Basic utilities
Directory management
mkdir directory Creates a new directory rmdir directory1 directory2 ... Removes directories
26
Basic utilities
Copying files
% cp file1 file2 Copies file1 to file2 % cp -i file1 file2 Copies file1 to file2; Prompts for confirmation % cp file1 dir1 Copies file1 to dir1 % cp -r dir1 dir2 Copies dir1 to dir2, recursively
27
Basic utilities
Moving/Renaming files
% mv file1 file2 Rename file1 to file2 % mv -i file1 file2 Prompts for confirmation % mv file1 dir1 Moves file1 to dir1 % mv dir1 dir2 Moves dir1 to dir2
28
Basic utilities
Removing files
% rm file1 Remove file1 % rm -i file1 Prompts for confirmation % rm -r dir1 Remove all contents of dir1, recursively % rm -f file1 Skip error messages and prompts
29
Basic utilities
30
Basic utilities
Printing files
lpr filename Sends the file to a printer lpq Shows the printer queue lprm Removes a printing job
31
Basic utilities
32
Basic utilities
Checking users/processes
who (shows the list of users currently logged in) whoami (shows your login name) finger name ... (shows information of a user) ps (shows the list of processes) kill [-9] process1 process2 ... Kills processes -9 option makes it mandatory
33
File type
Example
-rw-r--r-- 1 ccarpenter cs 867 Nov 18 20:13 test.c
File types (indicated by the starting character) - (regular file) d (directory file) l (symbolic link) % file test.c (lets you know the type of file) test.c: c program text
34
File permissions
Example
-rwxr-xr-- 1 ccarpenter cs 867 Nov 18 20:13 test.c
Group r-x
Others r--
What the characters mean r Read permission w Write permission x Execute permission
35
chmod
chmod change filename u user/owner + add permission g group remove permission o others = assign permission absolutely x execute
36
a all
r read
w write
chmod
% % % % % % chmod u+x myfile (allow my execution) chmod go-r myfile (disallow others reading) chmod g+w myfile (allow groups writing) chmod u-rw myfile (disallow my read/write) chmod a+x myfile (allow everyones execution) chmod g=r myfile (give group read-only permission) % chmod u+w,g-r myfile (allow my writing and disallow groups reading)
37
chmod
Octal numbers can be used for permission specification % chmod 700 myfile (disallow others access) % chmod 750 myfile (rwxr-x---)
others --000 0
38
matches any single character string [..] matches any one of the characters in the bracket
39
Example
$ ls a.c bb.c cc.d d.e $ ls *.c a.c bb.c $ ls ?.c a.c $ ls [ac]* a.c cc.d $ ls [A-Za-z]* a.c bb.c cc.d d.e $ ls ?.? a.c d.e
40
Pipes
Special characters
Terminal metacharacters
Interpreted by your UNIX terminal
% stty -a (displays all metacharacters) % stty erase ^b % stty erase ^h (set erase key to control-B) (set erase key to control-H)
42
Special characters
^C (Ctrl-C)
Terminates (interrupts) the current process % man pwd User Commands NAME pwd - return working directory name... ^C %
pwd(1)
43
Special characters
^D (Ctrl-D)
Terminates current shell, or indicates EOF (end-of-file)
44
VI editor
45
VI editor
2 Modes
Text Entry mode (Insert mode) Command mode
VI editor
Command mode
User can edit text here Press ESC (escape key) to enter this mode Supported operations Moving the cursor Deleting text Copying-and-Pasting text Replacing text Searching through text Searching and replacing text Saving or loading files Miscellaneous
47
VI editor
Cursor movement
Movement Up one line Down one line Right one character Left one character To start of line To end of line Down half screen Up half screen To line nn To end of file Key sequence <cursor up> or k <cursor down> or j <cursor right> or l <cursor left> or h ^ $ Ctrl-D Ctrl-U :nn<Enter> (or nnG) G
48
VI editor
Deleting text
Items to delete Character Word Line n Lines (from the current line) Current position to end of current line Block of lines All of the lines in the file All of the lines from line 1 to current line All of the lines from current line to end of file Two lines beginning from current line x dw dd ndd D :<range>d<Enter> :1,$d<Enter> :1,.d<Enter> :.,$d<Enter> :.,.+2d<Enter> Key sequence
49
VI editor
Copying-and-Pasting text
Action Copy current line Paste the copied text after current line Paste the copied text before current line n Lines (from the current line) Copy block of lines p P nyy (or nY) :<range>y<Enter> Key sequence yy (or Y)
50
VI editor
Replacing text
Items to replace Character Word Line r cw cc Key sequence
51
VI editor
52
VI editor
53
VI editor
54
VI editor
Miscellaneous
Action Redraw screen Undo the last operation Undo multiple changes made on the current line Join the next line with the current line Repeat the last operation Quit vi if work is saved Quit vi without saving Show line numbers Remove line numbers Ctrl-L u U J . :q :q! :set nu :set nonu Key sequence
55
VI editor
~/.exrc
You can store basic vi environment in .exrc file First go to your home directory and open the file: % cd ~ (or just cd) % vi .exrc Then insert your own vi settings, e.g., :set ts=3 :set autoindent :set number
56