UNIX Lecture 3
rm
Removes a file
yap{cuttsq}1: rm myFile
By default no confirmation message
Can request confirmation messages
yap{cuttsq}1: rm -i myFile
rm: remove myFile?
Very dangerous when used with *
yap{cuttsq}1: rm *
Even more dangerous when used in conjunction with -r flag
this gives recursive delete in any specified sub-directories, e.g.
yap{cuttsq}1: rm -r *
removes everything from the cwd downwards
There are file backup systems.....
Executing a command
Consider
yap{cuttsq}1: mkdir mscitDir
Command itself identifies a file somewhere in the system
it is a filename
contents of corresponding file can be executed
arguments available to executing code
How does the system perform the name->file mapping?
relative/absolute filename -> uses the specified file
e.g. /local/tools/ingres/bin/createdb
simple filename -> path search
path Searching
Concept of the path
consists of a list of directories within the system
.:/usr/lang:/usr/ucb:/usr/bsd/bin:/usr/bin:/bin:/usr/hosts:/usr/new:/local/sun4/bin:/local/tools/ingres/bin:/local/tools/ingres/utility
Whenever the shell receives a command, it
takes the command name
searches each directory in the path list in turn.
It looks for a file, executable to the current user, of the same name
and executes it if found
The which command tells you where a command was found in the path
yap{cuttsq}1: which mkdir
/usr/bin/mkdir
The Working Environment
The path is part of the environment in which the shell is embedded
Environment defined by environment variables
PATH, HOME, USER, TERM, MANPATH
used by the shell and also automatically made available to executing programs
printenv displays their current values
setenv allows new values to be assigned
yap{cuttsq}1: setenv PATH (. ~/bin /usr/bin /usr/ucb )
unsetenv allows variables to be removed
Local variables
Local variables are not automatically passed to sub-shells and executing programs
used just by the shell itself
some automatically declared on creation of shell, others declared by the user
Declared/assigned using set
set filec
set history=50
set /* prints out all locals */
Removed using unset
alias Command
One mechanism for allowing new commands to be defined
String substitution
yap{cuttsq}1: alias m more
whenever m is typed as command name, it is replaced by more
Used for convenient short-cuts
alias on its own displays all aliases
unalias removes the specified alias
Shaping your own environment
Tedious to type many setenvs & aliases on login
Two files in home directory specify default settings
.login and .cshrc
contain a number of cshell commands
.login executed when you log in
.cshrc executed when a new shell is created
examples of shell scripts which we shall see later
To experiment with your .cshrc
take a copy first in case you screw up!
edit the .cshrc - perhaps by adding some aliases
execute source .cshrc to see the effect
(provided youÕre in your home directory)
PATH could be extended by editing in new directories
Digression
files beginning with a . are hidden files in that ls does not show them
Usually used as set up files or special files to make an application work
display ALL files with ls -a
Printing - lpr
All printers connected to the Unix network
yes, they look like files - adding text to them results in the text being printed out!
Desired printer specified with -P flag
lpr -Plwbo507-1 myFile
PRINTER environment variable used to identify a default printer
setenv PRINTER lwbo507-1
lpr myFile
or else make aliases
alias lp1 lpr lwbo507-1
lp1 myfile
Print queues
To show the print queue on a particular printer
yap{cuttsq}1: lpq -Plwbo507-1
job: yap:fred; status: busy; source Appletalk
Rank Owner Job Files Total Size
active fred 91 fredsFile 4325 bytes
waiting cuttsq 92 myFile 24 bytes
To remove an item on the print queue (usually)
lprm -Plwbo507-1 92
PRINTER variable works with lpr, lpq, lprm