Unix and Shell Programming Basics.pdf
(
90 KB
)
Pobierz
Unix and Shell Programming Basics
Strona 1 z 46
CSE 178
Fall Semester 1995
Unix and Shell Programming Basics
Table of Contents
Introduction and Basic Unix Utilities
This Document
Operating System
Unix
Unix Utilities
Using the Unix Mail Facility
Unix Files and the Unix File System
Unix File Structure
Bourne and C Shell Basics, Redirection, Pipes, Processes
The Unix Shell
Information containing variables
The History Facility and History Substitution
Command Aliasing
Files that are used for initialization and termination
Information about Bourne Shell variables
Input/output redirection (Bourne and C Shells)
Pipelines and Processes (Bourne and C Shells)
Miscellaneous Commands
Shell Programming in the Bourne Shell
Creating new commands
Control Structures (for the Bourne Shell)
While Loops
Until Loops
The shift command
The shell logical operators
Miscellaneous Examples
The case statement
Here Documents
The shell trap command
Shell Signal Numbers
Using the Internet
Introduction and Basic Unix Utilities
This Document
In addition to being a set of class notes, these notes also exist as an interactive hypertext
document. This means there are embedded links to other documents and sites, such as John
Smith's extensive
UNIXhelp for Users
. Browsing these links, using a WWW browser, is not only
fun, but educational!
Also, don't miss out on using Usenet News and Electronic Mail to help you learn
Unix and Shell
Programming Basics
.
file://C:\Moje dokumenty\Unix and Shell Programming Basics.htm
00-12-03
Unix and Shell Programming Basics
Strona 2 z 46
Operating System
Definition:
A program which acts as an interface between the computer hardware and the user of
the computer.
1.
Provides an environment in which a user may execute programs.
2.
Controls the resources of a computer and allocates them among the users of the computer.
Goals:
1.
Make the computer easier to use.
2.
Efficient use of the computer's resources.
Manage memory.
Manage processes and CPU time and usage.
Control peripheral devices (e.g. disks, printers, terminals, modems)
Provide a file system that manages the long term storage of information (e.g.
programs,data,documents).
Unix
The name Unix refers to a family of computer operating systems (e.g. Ultrix, IBM Unix (AIX),
AT&T System V UNIX (UNIX=registered trademark of AT&T and USL (Unix Systems Lab)),
Berkeley Unix).
Definition:
An interactive multiuser operating system.
History
: Developed at AT&T Bell Labs in Murray Hill, New Jersey in 1969 by Ken Thompson.
Originally written in PDP-7 assembly language. Written in C in 1973.
Advantages:
1. Portability - Since most of Unix is written in the language C, it is quite portable; it runs on
micros to mainframes. This gives Unix a strong commercial advantage.
2. Easily modified -The source code is available and written in a high level language (C) so
the system is easy to adapt to different requirements.
3. Provides a rich and productive environment.
4.
Supports multi-tasking (asynchronous processes).
General Structure:
[[graphics - no textual representation.]]
The kernel controls the resources of the computer and allocates these resources among the users
of the computer.
Unix Philosophy: The power of a software system comes as much from the relationships among
programs as it does from the programs themselves.
1.
On their own many Unix tools perform very simple operations. (Tools philosophy:
separation of different functions into different programs.)
file://C:\Moje dokumenty\Unix and Shell Programming Basics.htm
00-12-03
Unix and Shell Programming Basics
Strona 3 z 46
2.
Simple tools can be easily combined to create powerful, general-purpose tools.
Unix Utilities
passwd
As soon as you log in to the Unix system for the first time change your password using this
command. You will be prompted for all needed information.
vi
The standard full-screen editor available under Unix.
Using Command mode
ZZ - save file and exit
:q! - exit without save
:w - write buffer to disk
h (left) j (down) k (up) l (right)
ndw
- delete n words (default for n = 1)
nx
- delete n characters (default for n = 1)
ndd
- delete n lines (default for n = 1)
-
- go to start of previous line
^
- go to first non-blank character of current line
O
- go to first column of current line
$
- go to end of current line
nG
- go to nth line of file (default for n = 1)
nyy
- yank and save n lines
p
- put down lines saved
Using INSERT MODE
<esc>
- exit INSERT mode
i
- enter INSERT mode ; insert to left of cursor
a
- enter INSERT mode ; insert to right of cursor
A
- enter INSERT mode ; add at end of current line
o
- enter INSERT mode ; add a new line after current line
O
- enter INSERT mode ; add a new line before current line
/<pat>
- search from cursor down for pattern <pat>
?<pat>
- search from cursor up for pattern <pat>
n
- go to next occurrence of last pattern indicated
N
- go to previous occurrence of last pattern indicated
[[graphics - no textual representation.]]
OPTIONAL
stty
sets I/O options on current output terminal. With no arg, reports terminal speed and settings
different than defaults. Some options are :
1.
all : print all normally used option settings.
2.
everything : print all information known to stty.
3.
raw : raw mode input ( no input processing (e.g. erase, kill,interrupt ).
4.
-raw : negate the raw mode.
5.
echo : echo back each character typed.
6.
-echo : do not echo characters.
7.
erase c : set erase character to c (default='#').
8.
kill c : set kill character to c (default='@').
9.
intr c : set interrupt character to c (default=ctrl ?).
10.
start c : set start character to c (default=ctrl q).
11.
stop c : set stop character to c (default=ctrl s).
file://C:\Moje dokumenty\Unix and Shell Programming Basics.htm
00-12-03
Unix and Shell Programming Basics
Strona 4 z 46
Example:
stty eof '^d' erase '^h' kill '^u' intr '^c'
These are the typical settings. Note the differences from the defaults given.
control characters
1.
ctrl-w : deletes the current command line word you are typing (word=any sequence of
non-blank characters).
2.
ctrl-d : end-of-file character.
3.
ctrl-c : interrupts current foreground process (In mail two ctrl-c characters kill the
mail message and save it in dead.letter).
4.
ctrl-s : suspends output being printed to screen.
5.
ctrl-q : resumes printing of suspended output.
6.
ctrl-r : moves to next line and redraws command line.
7.
ctrl-h : erases character just typed on command line.
cat
displays the contents of a text file. This command is actually used to concatenate two or
more files. Since the output goes by default to the standard output, cat can be used to
display at the terminal screen the contents of a single file (i.e. a single file with nothing
concatenated to it).
1.
-e : marks the ends of lines of input files with dollar signs.
2.
-s : suppresses the warning message when cat can't find an input file.
3.
-t : marks each tab in input files with ^I.
4.
-v : cat displays nonprinting characters (other than tabs and newlines) found in input
files.
5.
-n : prepend line number to output line
Syntax:
cat <file names>
Examples:
$ cat prog.c
$ cat file1 file2 file3
$ cat -v -t file1
ls
with no arguments prints a list of the names of the files in the current working directory.
With directory arguments a list of files in each directory is printed. With a file argument
that filename is listed. Some options are:
1. -a : displays all entries including those that begin with a period.
2. -c : sorts entries by time of last inode modification.
3. -d : displays directories only.
4. -F : marks entries in list (directory/ , socket= , symbolic link@ , executable_file*)
5. -l : lists mode, number of links, owner, size(bytes), time of last modification. Special
files have size field replaced with major and minor device numbers. (mode first
character: d=directory, b=block-type special file, c=character type special
file,l=symbolic link,s=socket,-=plain file) (mode permissions:user-group-other)
6. -s : displays size (in blocks) of each file (given as first entry)
7.
-r : sorts entries in reverse alphabetic or time order
file://C:\Moje dokumenty\Unix and Shell Programming Basics.htm
00-12-03
Unix and Shell Programming Basics
Strona 5 z 46
8.
-i : prints the inode number of each file
9.
-u : sorts by time of last access (read or executed)
10.
-t : sort (Example: Sort by last inode modification time = ls -ctl)
11.
-1 : print in a single column (
Examples:
ls -1
or
ls -ct1
)
Syntax:
ls <file names>
Examples:
$ ls -l draw
-rwx------ 1 jpl 24576 Oct 18 12:45 draw
permissions = -rwx------
number of links = 1
meaning ->
owner userid = jpl
size in bytes = 24576
date of last modification = Oct 18 12:45
filename = draw
Three times are recorded and available when using ls.
1.
Inode modification time (c)
2.
File contents modification time. (default)
3.
Access time (u)
rm
removes the named files.
1.
-i : ask before removing each file listed (interactive mode).
2.
-r : remove listed directories and all their subdirectories
3.
-f : silently remove files for which one does not have write permissions.
Syntax:
rm <file names>
Examples:
$ rm file1 file2
$ rm prog.c
$ rm -ri workdir
more
displays the named files one screenful at a time.
1.
+n : starts displaying first file at line number n
2.
-n : specifies number of lines to display on screen. (The default is obtained from
variable TERM and info in /etc/termcap.
Syntax:
more <file names>
Examples:
$ more file1 file2
$ more +25 prog.c
rmdir
file://C:\Moje dokumenty\Unix and Shell Programming Basics.htm
00-12-03
Plik z chomika:
Phoob
Inne pliki z tego folderu:
So15 - Programowanie wspolbiezne.pdf
(52 KB)
So10 - Rozproszona pamiec dzielona 1.pdf
(111 KB)
abs-guide.pdf
(895 KB)
BASH - Programowanie w powloce.pdf
(343 KB)
LinuxPG.pdf
(481 KB)
Inne foldery tego chomika:
ALG
AM2
ANG1
ANG2
ASD
Zgłoś jeśli
naruszono regulamin