Title: CSCI 553: Networking III Unix Network Programming Spring 2006
1CSCI 553 Networking III Unix Network
ProgrammingSpring 2006
2Getting Help
- dharter_at_nisl man ls
- LS(1) User Commands
LS(1) - NAME
- ls - list directory contents
- SYNOPSIS
- ls OPTION... FILE...
- DESCRIPTION
- List information about the FILEs (the
current directory by default). - Sort entries alphabetically if none of
-cftuSUX nor --sort. - Mandatory arguments to long options are
mandatory for short options - too.
- -a, --all
- do not hide entries starting with .
3less/more commands
- COMMANDS
- In the following descriptions, X means
control-X. ESC stands for - the ESCAPE key for example ESC-v means
the two character sequence - "ESCAPE", then "v".
- SPACE or V or f or F or PageDown
- Scroll forward N lines, default
one window (see option -z - below). If N is more than the
screen size, only the final - screenful is displayed. Warning
some systems use V as a - special literalization character.
- b or B or ESC-v or PageUp
- Scroll backward N lines, default
one window (see option -z - below). If N is more than the
screen size, only the final - screenful is displayed.
- UpArrow or j
- Scroll back 1 line.
4Command Line Editing
- dharter_at_nisl man readline
- READLINE(3)
READLINE(3) - NAME
- readline - get a line from a user with
editing - DESCRIPTION
- readline will read a line from the
terminal and return it, using - prompt as a prompt. If prompt is NULL or
the empty string, no prompt - is issued. The line returned is allocated
with malloc(3) the caller - must free it when finished. The line
returned has the final newline - removed, so only the text of the line
remains. - readline offers editing capabilities while
the user is entering the - line. By default, the line editing
commands are similar to those of - emacs. A vi-style line editing interface
is also available. - This manual page describes only the most
basic use of readline. Much - more functionality is available see The
GNU Readline Library and The
5Command Line Editing
- Commands for Moving
- beginning-of-line (C-a)
- Move to the start of the current
line. - end-of-line (C-e)
- Move to the end of the line.
- forward-word (M-f) (Ctrl -gt)
- Move forward to the end of the next
word. Words are composed - of alphanumeric characters (letters
and digits). - backward-word (M-b) (Ctrl lt-)
- Move back to the start of the
current or previous word. Words - are composed of alphanumeric
characters (letters and digits). - Commands for Manipulating the History
- accept-line (Newline, Return)
- Accept the line regardless of where
the cursor is. If this - line is non-empty, it may be
added to the history list for - future recall with add_history().
If the line is a modified - history line, the history line
is restored to its original - state.
Killing and Yanking kill-line (C-k)
Kill the text from point to the end of
the line. unix-word-rubout (C-w)
Kill the word behind point, using white space
as a word bound- ary. The killed
text is saved on the kill-ring. Completing
complete (TAB) Attempt to
perform completion on the text before point.
The actual completion performed is
application-specific. Bash, for
instance, attempts completion treating the text
as a variable (if the text begins
with ), username (if the text begins with
), hostname (if the text begins with _at_),
or command (including aliases and
functions) in turn. If none of these produces
a match, filename completion is
attempted. Gdb, on the other hand,
allows completion of program functions and
variables, and only attempts
filename completion under certain
circumstances.
6File Attributes
- dharter_at_nisl ls -lsF
- total 840
- 8 drwxr-xr-x 2 dharter dharter 4096 May 16
2005 bin/ - 16 -rwxrw-r-- 1 dharter dharter 11684 Jun 17
2005 cp.txt - 8 drwxr-xr-x 2 dharter dharter 4096 Sep 16
1538 Desktop/ - 8 -rw-rw-r-- 1 dharter dharter 1762 May 6
2005 Diagram1.dia - 8 -rw-rw-r-- 1 dharter dharter 1658 May 6
2005 Diagram1.dia.auto - 80 -rw-rw-r-- 1 dharter dharter 70189 Sep 16
1443 dvdbackup.c - 224 -rwxr--r-- 1 dharter dharter 218730 Oct 21
1352 gaotv5.pdf - 140 -rw------- 1 dharter dharter 132728 Oct 21
1352 gaotv5.ps - 4 -rw-rw-r-- 1 dharter dharter 0 Oct 18
1310 java.log.30791 - 288 -rw-rw-r-- 1 dharter dharter 283329 Sep 16
1501 libdvdcss.tar.bz2 - 8 -rw------- 1 dharter dharter 1520 Feb 18
2005 mbox - 8 -rw-rw-r-- 1 dharter dharter 1745 Mar 6
2005 pathdef.m - 8 -rw-rw-r-- 1 dharter dharter 663 Mar 20
2005 .reminders - 8 drwxrwxr-x 7 dharter dharter 4096 Jan 11
1229 tmp/ - 8 -rw-rw-r-- 1 dharter dharter 56 Mar 19
2005 tmp.remind - 8 -rw------- 1 dharter dharter 190 May 18
2005 unison.log - 8 drwxr-xr-x 14 dharter dharter 4096 Sep 19
1955 work/
7File Types
- Field 2 describes the files type and permission
settings. Here is the output from previous ls - dharter_at_nisl ls -lsF
- 8 drwxr-xr-x 2 dharter dharter 4096 May 16
2005 bin/
8File Permissions
- dharter_at_nisl ls -lsF
- 8 drwxr-xr-x 2 dharter dharter 4096 May 16
2005 bin/
File Type
User (owner)
Group
Others
- dharter_at_nisl chmod o-rx bin
- dharter_at_nisl ls -lsF
- 8 drwxr-x--- 2 dharter dharter 4096 May 16
2005 bin/
9Searching Files
- grep search a file for a pattern where the
pattern to search can be a regular expressions
(see Appendix A)
10Finding files
- The find utility can locate files, and it can do
more, such as perform actions on a set of files
that satisfy specific conditions.
11awk
- awk scans files and performs an action on all of
the lines that match a particular condition. - High-level scripting languages, like perl and
python, in general have superseded awk for these
types of text processing tasks, but knowing awk
can still be useful for small shell commands.
12Shell Metacharacters
13Redirection
- Output redirection
- cat gt tmp.dat
- cat gtgt tmp.dat
- Input redirection
- mail glass lt tmp.dat
14Filename substitution (Wildcards or File Globbing)
- ls .c
- ls ?.c
- ls ac
- ls dir/.c
- ls .c .h
- ls 2/?.? ?.?
15Pipes
- The shell allows you to use the standard output
of one process as the standard input of another
process by connecting the processes together via
the pipe () metacharacter. - ls wc w
- cat /etc/passwd awk F print 1 sort
16Beginning Shell Programming
- Command substitution
- dharter_at_nisl echo the date today is date
- the date today is Wed Jan 25 113210 CST 2006
- dharter_at_nisl echo there are who wc -l
users on the system - there are 3 users on the system
- Sequences
- dharter_at_nisl date pwd ls
- Wed Jan 25 113356 CST 2006
- /home/dharter
- bin dvdbackup.c
mbox unison.log - cp.txt gaotv5.pdf
pathdef.m work - Desktop gaotv5.ps
.reminders - Diagram1.dia java.log.30791
tmp - Diagram1.dia.autosave libdvdcss-1.2.9.tar.bz2
tmp.remind - Conditional Sequences
- cc myprog.c a.out
- cc myprog.c echo compilation failed
17Background Processing
- Commands followed with the metacharacter will
be executed in a subshell as a background
process. - find / name .c print gt find.txt
- 2788
-
- jobs
- kill 1
- fg 1
- ctrl-z
- bg
18Environment Variables
- Each shell has a predefined set of environment
variables.
19Environment Variables
- dharter_at_nisl echo HOME
- /home/dharter
- dharter_at_nisl echo PATH
- /usr/kerberos/bin/usr/java/j2sdk1.4.2_09/bin/usr
/local/bin/bin/usr/bin/usr/sbin/usr/X11R6/bin
/opt/pbs/bin/home/dharter/bin/opt/kernel_picker/
bin/opt/pvm3/lib/opt/pvm3/lib/LINUX/opt/pvm3/bi
n/LINUX/opt/env-switcher/bin/opt/c3-4//opt/pbs/
lib/xpbs/bin - dharter_at_nisl echo USER
- dharter
- dharter_at_nisl echo SHELL
- /bin/bash
- dharter_at_nisl echo TERM
- xterm
20Finding a Command PATH
- dharter_at_nisl echo PATH
- /usr/kerberos/bin/usr/java/j2sdk1.4.2_09/bin/usr
/local/bin/bin/usr/bin/usr/sbin/usr/X11R6/bin
/opt/pbs/binpeep/opt/kernel_picker/bin/opt/pvm3/
lib/opt/pvm3/lib/LINUX/opt/pvm3/bin/LINUX/opt/e
nv-switcher/bin/opt/c3-4//opt/pbs/lib/xpbs/bin - dharter_at_nisl which who
- /usr/bin/who
- dharter_at_nisl ls bin
- aeonfvwm2 beep.py ClusterServer.py
maketd skill.py - aeongnome cluster-client.py cnlgnome
moncluster spsclust.py - bck-full.py ClusterClient.py killre.py
setdisp sps.py - bck-inc.py cluster-server.py lokignome
skillclust.py - dharter_at_nisl which beep.py
- /usr/bin/which no beep.py in (/usr/kerberos/bin/
usr/java/j2sdk1.4.2_09/bin/usr/local/bin/bin/us
r/bin/usr/sbin/usr/X11R6/bin/opt/pbs/bin/home/
dharter/bin/opt/kernel_picker/bin/opt/pvm3/lib/
opt/pvm3/lib/LINUX/opt/pvm3/bin/LINUX/opt/env-sw
itcher/bin/opt/c3-4//opt/pbs/lib/xpbs/bin) - dharter_at_nisl beep.py
- bash Beep.py command not found
- dharter_at_nisl ./bin/beep.py