I'm not going to pretend that UNIX is fun or easy. The best operating system is one you don't even realize is there, because it's so natural to use, or because you've absorbed all its conventions as though they were physical law. When you start out with a new operating system, it's torture, and there's no way to hide it. We need to know certain facts about the operating system in order to create, organize and transfer files, and to execute the programs we're interested in.
Back to TABLE OF CONTENTS.
The computers we will use are running the LINUX operating system, which is a variety of UNIX. To use the machine, you need a username and password. Once the machine gives you access, you begin your session with a work area known as your home directory. You will be assigned a limited amount of space that you can arrange as you like, and which will be available to you the next time you log in. Your sessions will always start in this place, although you can make new work areas that will be subdirectories of this one. To see the name of your present working directory, type:
pwdThere may already be a few files in your home directory. Type:
lsor
ls -lato see what's there. You will often want to make subdirectories of your main directory, in which you can store certain groups of files. To do this, choose a name for the subdirectory, such as notes and type
mkdir notesNow when you issue the ls command, a new notes object should show up. If you used the ls -la command, you will notice that notes is listed in a way that indicates it is a directory. To move your working area to the notes directory, type
cd notesNow type pwd and verify that you have moved. The "parent directory" (where we were before) has the symbolic name "..", and so to move back up there, you can just type:
cd ..To get rid of the subdirectory, type
rmdir notesUnix directories can have very long official names, called the full or absolute path name. To see how complicated these names can be, note that when you issue the pwd command, your present working directory is described with this long name. Sometimes these names are necessary. If, when moving around or getting a file, it's not in a directory below you, or in the directory above you, it may be necessary to use the full path name to specify the location. For instance, we can issue the commands:
ls /usr/local/binto see what's in that directory, or we can jump to another place and back again by typing:
cd /usr/manNote in the last example that a cd command with no directory specified will send you back to your home directory.
pwd
cd
Back to TABLE OF CONTENTS.
Everything on a UNIX system is a file; in particular, everything is stored in some directory, and will show up with the appropriate ls command. This includes your own text files, executable programs, and directories themselves.
We will need to create our own text files. To do so, we need an editor program. Unfortunately, the editors on most UNIX systems are pretty bad. You can always edit on your favorite home system, and ftp files back and forth, but it helps to have some way to do editing locally. You might already know how to use the fancy emacs or vi editors. I will discuss two simpler ones, edit and xedit.
Back to TABLE OF CONTENTS.
edit is a "line editor" - that is, it edits and displays your file a line at a time, without using a graphical interface. You start the program by typing something like
edit my_file.txtand then type a meaning append to indicate that you want to add stuff to the file. What you type now will go into the file my_file.txt, until you type a single period in column 1. Then type w to save the changes, and q to exit. Here, with some helpful indentation, is a suggestion of how this works:
edit my_file.txt a Here is an example of a file being created with the EDIT editor. . w qOnce you've made the file, you want to go back and make changes in it. Here are some commands you can give:
17 goes to line 17 $ goes to the last line .= print the number of the current line r FRED copies the text of the file FRED into this file a append text after the current line i insert text before the current line d delete the current line m 23 move the current line to just after line 23 p print the current line s/the/one change the first "the" to "one" on the current line /tag find the next line containing "tag"Many commands allow you to specify a range of lines. For instance
10,20p prints lines 10 to 20.
Back to TABLE OF CONTENTS.
xedit is a simple screen editor, which shows you a chunk of lines from your file, and allows you to scroll smoothly up and down through the file, as though it were printed on a very long sheet of paper.
Thus, to enter and alter text is very simple. You simply position the cursor in the desired location and click. You can highlight text to be cut and then paste it elsewhere or discard it.
Search is done using Control-S, and replace with Control-R. Menu options allow you to save the file, read in a different file, or quit.
Back to TABLE OF CONTENTS.
A file is placed in a directory, usually your present working directory. If you're in your home directory, and you run the editor and create the file bob, then when you leave the editor, bob will be sitting in that directory. You might not like the name bob. In that case, the mv command can be used to rename it:
mv bob daveMore often, the mv command is used to actually move the file. For instance, to move bob into the subdirectory notes:
mv bob notesor
mv bob notes/bobThe first command is a little risky. If we don't actually have a notes subdirectory, then the command changes the name of the file bob to notes, which is not what we wanted. The second command is safer. If the notes directory doesn't exist, the command won't be carried out.
The cp command will let us make a copy of the file:
cp bob daveThe ls command can be used to get a directory lising of just a particular file instead of the whole directory:
ls bobTo examine the contents of a file, type
more bobTo delete a file, type
rm bob
Back to TABLE OF CONTENTS.
You can copy files to or from a floppy disk inserted into the computer. This can be a handy way to save your work from one lab session to the next. You just need the cp command, and the correct path name of the floppy drive:
cp my_file.txt /dev/floppy
You can copy files to or from another computer, using the ftp program. For example, if you're logged in on a lab computer, and want to get a file from your account on Euler, you might type:
ftp euler (Euler will ask you to log in:) my_name my_password Now you might want to move to a subdirectory on Euler. cd euler_directoryTo copy a file from the lab to Euler, use the put command instead of get instead.
get my_file.txt
quit
Back to TABLE OF CONTENTS.
A compiler converts text files of C or FORTRAN source code into new executable programs for finding roots of polynomials or solving differential equations. Here is a tiny C program which you can type into a file called sample.c:
#includeIn order to run this program, you need to compile and load it:#include void main ( void ) { int i; float w; float x; w = 10.0; x = 1.0; for ( i = 0; i < 6; i++ ) { printf ( "X = %f X^2 = %f\n", x, x * x ); x = 0.5 * ( x + w / x ); } }
cc sample.c(On some machines, the compiler might be called gcc instead.) This creates a program called a.out which we should rename:
mv a.out sampleand now we can run it by typing:
sample
To do a similar thing with FORTRAN, here is a sample program.
program main integer i real w real x w = 10.0 x = 1.0 do i = 0, 5 write ( *, * ) 'X = ', x, ' X^2 = ', x * x x = 0.5 * ( x + w / x ) end do stop end(Make sure each line begins with 6 blank spaces!). In order to run this program, you need to compile and load it:
f77 sample.c(On some machines, the compiler might be called g77 or f90 instead.) Again, this creates a program called a.out which we should rename:
mv a.out sample2which can then be run as before.
Back to TABLE OF CONTENTS.
Back to the MATH2070 page.
Last revised on 04 January 2000.