Transcript Document

More Unix
Naomi Altman
Directories
Directory = folder
mkdir - makes a new directory
rmdir - removes an empty directory
cd mydirectory
cd
pwd
.
../
- moves you into a directory
- moves you to "home"
- names the current directory
- is the current directory
- is the directory above the current
Environment
printenv
Prints the settings for your current Unix environment.
These can be changed using "set".
This is dangerous - you can totally mess up your
system by resetting variables in the environment.
It is also very useful - e.g. you can set up mail
folders, auxillary storage locations, commands.
Most of the settings are determined by the files
".cshrc" and ".login"
Paths
A path is a set of directories to search for commands
and files.
Generally, you have 2 paths set up - one for
commands, programs, etc
- one for documentation to be found by "man"
echo $path
Sometimes you may "lose" a program because it is
not in your path.
whereis R
Adding to your Path
set mypath (. usr/local/bin/R)
set path ($path $mypath)
You can add this to the .cshrc file (using the text
editor)
File Names
Any number of characters and numerals, as well as
".","_" or spaces, but the name should start with a
letter. Upper and Lower case are different - i.e.
myfile and MyFile are different names.
Extensions are not used by Unix, although they may
be used by some programs (e.g. Netscape
recognizes .htm and .html) or they may be created
by some programs (e.g. compilers)
Filenames ending in % are meant to be temporary
files and may be removed during "clean-up"
operations.
Wild Cards
Many Unix commands recognize "regular
expressions". These allow you to search for files or
directories, or to find words within files.
* matches anything of any length
? matches a single character
[x-y] where x and y are numbers or letters matches a
single character including x and y and everything
that normally falls between them.
Matching
ls -a
 ls .g*
 ls .g[a-c]*
 ls .g?conf

Beware the dreaded rm *
(Sad but true):
The week before my dissertation draft was due, I ran
out of disk space. To remove temporary files I
typed rm * % instead of rm *%. OOPS!!!
On our system, rm has an "alias" rm -i which asks
before removing.
Alias
Which reminds me that you can make new
commands:
alias MyCmdName "commands"
creates a new command named MyCmdName that
executes all the commands in the ""s
The new command name will overwrite any Unix
command with the same name (so be careful).
History
history (show command history list)
 % !! (recall last command)
 % !-3 (recall third most recent command)
 % !5 (recall 5th command in list)
 % !g (recall last command starting with g)


% set history=100
Also !!$ is the result of the last function.
ls
rm !!$
Writing Software


The make command allows programmers to manage large
programs or groups of programs. It aids in developing
large programs by keeping track of which portions of the
entire program have been changed, compiling only those
parts of the program which have changed since the last
compile.
The make program gets its set of compile rules from a text
file called makefile which resides in the same directory as
the source files. It contains information on how to compile
the software, e.g. the optimization level, whether to
include debugging info in the executable. It also contains
information on where to install the finished compiled
binaries (executables), manual pages, data files, dependent
library files, configuration files, etc.
Writing Software
I can no longer tell you the details of creating a
makefile, but it was extremely useful when I was
writing c and fortran programs for my dissertation.
(These days, that would be c++, java, etc) because
it automated the updating process.
The Unix Philosophy
Unix was written as a toolkit (The LEGO
philosophy).
The developers provided nails, screws, hammers, etc
and expected others to write software.
The pieces all fit together - if you don't have the piece
you need, you can build it.
Because of this, Unix was written for programmers,
not users.
The user interfaces have been built on top of the
toolkit.
R and the Unix Philosophy
S was a statistical package built to use with Unix.
It followed the Unix philosophy.
R is a modern version of the original S.
When you are running R in Unix, you can execute
"shell commands" by proceeding them by !
e.g. ls() is a list of objects in the R workspace
!ls is a list of objects in the directory in which
you are running R.
Why Bother with Unix/Linux
Unix was written by a bunch of programmers to
facilitate programming.
So, it was written to be easy for programmers to
extend, which they have.
Lots of cool programming tools and environments are
available.
Unix has much better memory management than
Windows, which allows e.g. background
computing, and stringing together many CPUs (a
cluster) into a supercomputer.
Linux Clusters at Penn State
http://gears.aset.psu.edu/hpc/systems/