Unix Stuff
- how to print man pages
- list of signals
- Single Unix Spec
- some useful shell environment variables
- redirecting
STDERR
- determine which process has which file open.
- using ftp clients in scripts
man Pages, printing of
To have man
format a man page that's not properly installed
in the MANPATH
environment variable:
man -l $FILE_NAME
To print man pages, or at least format them nicely for proper printing:
groff -man $MANFILENAME > man_page.ps
under Solaris:
export TCAT=/usr/lib/lp/postscript/dpost
man -t $COMMAND > man_page.ps
To find the file containing the man page, look through the directories in $MANPATH.
Signals
Greatest Hits:
SIGHUP | 1 | Hangup detected on controlling terminal or death of controlling process |
SIGINT | 2 | Interrupt from keyboard |
SIGQUIT* | 3 | Quit from keyboard |
SIGILL* | 4 | Illegal Instruction |
SIGABRT* | 6 | Abort signal from abort(3) |
SIGFPE* | 8 | Floating point exception |
SIGKILL | 9 | Kill signal |
SIGSEGV* | 11 | Invalid memory reference |
SIGPIPE | 13 | Broken pipe: write to pipe with no readers |
SIGALRM | 14 | Timer signal from alarm(2) |
SIGTERM | 15 | Termination signal |
see also: man 7 signal
, hint: many other signals exists.
Unix Specification
The Open Group has a lovely online specification defining what a true Unix® system consists of.
Environment Variables
- $$: pid of current process
- $?: exit status of last command executed. Success is indicated by 0
Redirect STDOUT and STDERR
some_cmd > output 2>&1
Redirecting STDERR to a pipe
some_cmd 2>&1 | some_other_cmd
Determining open files
To determine who has some file open (for example when vi complains that you may only open some file read-only):
fuser some_file
at least on Linux, it's also possible to determine which process is blocking that port you need to listen on:
fuser -n tcp $PORT_NUMBER
To do the opposite, i.e. determine which files a process has currently
opened, use lsof -p $PID
ftp, use of client in scripts
The trick to using ftp
in a shell script is to get it to refrain from
attempting "auto-login" during initial connection.
ftp -n localhost <<END_QUOTE # -n = no autologin
quote USER $USER
quote PASS $PASSWORD
# send arbitrary commands here, e.g. GET file.txt
END_QUOTE