Notes 31 35
Notes 31 35
UNIX 31
• ls -lrt This lists the elements contained within the working directory in detailed
form, also giving the ordering by files most recently modified.
• rm file This removes the file named file from the directory.
• cp file1 file2 This copies the file named file1 into the file named file2. If file2 already
exists, it is overwritten by file1.
• mv file1 file2 This 1) moves the file named file1 into the file named file2, and 2) removes
the file named file1. If file2 already exists, it is overwritten by file1.
• mkdir directory This creates the directory named directory within the working direc-
tory.
• rmdir directory This removes the directory named directory. The directory must be
empty in order to remove it.
• cat file Concatenate (i.e. print to the screen) the contents of file.
• more file Print to the screen the contents of file one screen at a time and use the space
bar to move down in the file.
• less file Like more except one can use arrows or j, k keys to navigate up and down
in file.
• UNIX command & Execute the process UNIX command in the background so as to
keep the terminal window available for user input.
One should note that other operating systems such as OS-X or Microsoft Windows have
file system devices such as OS-X’s “Finder” which give a WYSIWYG view of the UNIX tree
structure of organizing files. The two approaches are entirely compatible, and in fact can be
applied to arrange the same files. One is simply more visual than the other.
A file can be identified by its local address as long as the user resides in the proper
directory. For example to view the file helloworld.f90, one first insures it lives within the
present directory, and then executes
If the user resides in a different directory and still wishes to view the same file without first
navigating to that directory, one can used the absolute address, for example
A highly useful feature of most modern UNIX implementations is the arrow keys’ ability
to recall previous commands and edit them. It is difficult to display this without an actual
demonstration.
Here we illustrate some of the power of UNIX commands. The user may want to copy all
of the sample Fortran programs from the course home space to the user’s personal home
space. Since at Notre Dame both the course home space and the user’s home space are all
within AFS, and because the course home space is a public directory, copying is easy and can
be done in a few simple commands. The sequence of commands is described as follows:
4. Copy all files with an .f90 extension into your new directory.
Here mkdir made the new directory programs. We then moved into the directory programs,
via the cd command. We then listed the files within programs and found that it was empty.
We then copied all files with the .f90 extension into the existing directory, indicated by
the “dot”, [.], shorthand for the existing directory. We then re-listed the programs in the
directory and found ten new programs listed.
Here, we summarize a few of the key concepts of this chapter. Problems are often formu-
lated in words, which can be ambiguous. Some problems are amenable to mathematical and
computational analysis, and a challenging chore is to translate imprecise words into precise
computer code. The code to solve the posed problem is based upon a logical construct known
as an algorithm. An algorithm is much like a recipe for cooking. An important element of
most good scientific computing task involves what is known as object-oriented programming.
Such an approach relies upon identifying repetitive tasks and writing a single algorithm for
a task that is commonly executed as part of solving a larger problem. These building blocks,
known as objects can be highly refined and optimized since they will be repeated many times
in the course of a calculation. One might imagine developing a sub-algorithm for performing
matrix inversion within a larger problem that requires inversion of many matrices of different
types. Rather than write separate code for each matrix inversion, one writes one subroutine
to invert matrices of arbitrary dimension, provided of course they are invertible. Then that
subroutine may be called upon many times within the more general algorithm.
35