Chem 7520 Crash Course

Throughout this page, the prompt will be signified by “>” the beginning of a line (you do not this symbol, just everything after it).

Navigation

When you first log in, you will be placed in your home directory. To see what this directory is named, type:

>

For example, my directory will give me:

> pwd /uufs/chpc.utah.edu/common/home/u0764443

Directories in Unix are separated by “/ ”. Everything before your user name in the line above is just a series of directories that CHPC maintains. As far as you’re concerned, the directories that you need start with your own.

To see what is contained in the current directory, type:

>

You may see some names, as well as some that end in “/”. The latter are sub-directories. The setup script that I had you run yesterday should have created a directory called “qchem/”.

In order to change directories, use the “” command. For example, to switch to the qchem sub-directory, type

> cd qchem

Using

> cd qchem/ would also work. Try examining the contents of this directory with “ls”.

To navigate up a level, use

> cd ..

The two-period notation always means “up one level from here”. In order to navigate back to your home directory, you can always just type

> cd

You can also use detailed path names to navigate. Let’s say that I am in my qchem/ directory, but I want to switch to my chem7520 directory, is a also in my main directory: > pwd /uufs/chpc.utah.edu/common/home/u0764443/qchem > cd ../chem7520 > pwd /uufs/chpc.utah.edu/common/home/u0764443/chem7520

You should be able to navigate between directories using these few commands.

Handling files

Most file-handling actions in Unix can be accomplished by “”, “”, and “”. These functions are copy, move, and remove (delete), respectively.

To copy a file (“fileA”) to another file (“fileB”):

> cp fileA fileB

To move a file (“fileA”) in my current directory to another one (“dirB”):

> mv fileA dirB/

To rename a file (“fileA” to “fileB”), we also use “mv”:

> mv fileA fileB

The actions can also be combined:

> mv fileA dirB/fileB

To delete a file (“fileA”), use:

> rm fileA

To delete a directory, use “rm –r” (the –r stands for “recursive”):

> rm –r dirB/

To suppress the confirmation of “rm”, use “-f”:

> rm –rf dirB/

Warning: Be very careful when using the “-rf ” combination! Unix does not use a “recycle bin”, so once it’s been rm’, it’s gone. Never ever use this command in your home directory!!! (I’ve seen it happen…not pretty.)

Another trick that is often used is the “ * “ character. It is a “wild card” character. For example,

> ls q* will list all of the files in the current directory that begin with the letter “q”. Similarly,

> rm *.xyz will delete all files with the “.xyz” extension. Running programs

Running a program in Unix is pretty simple: just type the name of the program. The commands that I’ve given above (cd, ls, mv, etc.) are all technically programs, and we just typed their names. If I gave you a program called “myprogram” in a subdirectory called chem7520, the procedure would be:

> cd > cd chem7520/ > myprogram

The only caveat to these procedures is that the program must be “in your path”. The has a list of directories in which it knows to look for programs (these are called “your path”). If you just type the name of the program, it looks through this list. If the program happens to be somewhere outside of your path, it will complain. In this case (assuming that the program is in your current directory), just type:

> ./myprogram

This command—the single —means “the current directory”, so the above line means “run myprogram from here”. Hopefully you won’t need to use this version, but it sometimes happens.

For reference, you can always view your path by typing

> $PATH

(If you want to add a directory to your path, ask me how.) System variables are denoted by the “$” character. For example, an alternative method to listing your home directory is by typing

> echo $HOME

The “echo” command basically just writes things to the screen. Similarly, you can view the machine that you’re logged into by typing

> echo $

Making directories

Above, we established how to move between directories. You can create your own with the “” command. For example, to a directory called “mydir” in your home directory, type

> cd > mkdir mydir

You can then type “ls” to see it now appear.

Viewing files

To view the contents of a file, you have many options. A very simple one is the “more” command. This program just prints the contents of the file to the screen. The spacebar proceeds down by a page. This program is not for editing, just viewing.

For editing files, you again have many options. My personal favorite is “”, but this program has a steep learning curve (as we experienced Thursday ). Other popular options include “nano”, “emacs”, “gedit”, etc. We’ll do a separate training on text editors soon. Using the program on the problem set

You are asked in the problem set to run the “fourier1d” program. Below are some helpful hints in how to do this.

Let’s first make a directory where you can do all of your work. Here, I’ll call the directory “probset1”

> cd > mkdir probset1 > cd probset1/

The fourier1d program currently exists in my directory. Since my uNID is u0764443, this directory is called

/uufs/chpc.utah.edu/common/home/u0764443

Two other options exist for using this directory: 1. From your home directory, my directory will be named “../u0764443/” 2. The “ ~ “ symbol is mapped to the level of all of the usernames. (So “cd ~/” is another way to get home.) In this case, we’re using my directory, which is ~u0764443.

Now that you’re in your probset1/ directory, you can copy my program by typing:

> cp ~u0764443/chem7520/fourier1d .

The single period means “put it here”. (It will use the original file name in this case. If you wanted to copy and rename (to “newname”) at the same , you would type “cp ~u0764443/fourier1d newname”.)

Running the program just involves typing the name of the program, followed by the options detailed in the problem set. If you get a “command not found” error, try using “./ “ in front of the filename.

Plotting

Part of the problem set requires you to plot graphs. You have two options: 1. Copy the data files to your own machine (see below) and plot them in your favorite program…possibly Excel. 2. A better method would be to use gnuplot, which is built in to Unix operating systems. This program (like Unix itself) requires learning a few commands, but it’s pretty easy to get started. [Note to Windows users: see Xming instructions below.]

Let’s assume that you’re in your probset1/ directory. To run gnuplot, just type

> gnuplot

The program will start, and you will receive (yet another) command prompt. To plot a function, use the “plot” command. For example, to plot a line, type

> plot 3*x

The x and y ranges can be adjusted with

> set xrange [-4:10]

(and similar for yrange). To reset settings, such as xrange, use the “reset” command.

To plot data files, put them in quotes:

> plot “VofX.dat” By default, gnuplot will just plot the data points. You can also plot with connected lines by using

> plot “VofX.dat” with lines

You can increase the line thickness with

> plot “VofX.dat” with lines linewidth 3 (bigger number = thicker lines)

This all works great for viewing plots, but saving them is a little more difficult. To make a jpeg plot, use: > set terminal jpeg > set output “filename.jpg” (where filename is what you want to name the plot) > plot “VofX.dat” with lines

The above commands will now not generate a plot window for you to view. They will, however, make a graphic called filename.jpg in your current directory. I suggest that you make your plots by viewing them first, then generating them for the problem set.

(Note: gnuplot has several terminals available, including jpeg, gif, and even eps. Use whatever format you prefer.)

Great …now I have a file on the cluster. How do I put it on my computer? Windows users: You can use the “file transfer” version of SSH SecureShell to navigate to your files. It acts just like Windows Explorer. (Open it by clicking the file-folder icon in the row below the menu bar.) Drag the files from one side to the other to transfer them. Mac users: There may be a built-in graphical option like the Windows instructions above, but I don’t know of one. (Google tells me that Cyberduck might work.) Another option is to use “scp” from the terminal window. Its syntax is almost identical to “cp”, except that you have to specify the machine from which you’re copying. From a new terminal window (on your machine, not connected to the clusters), type > scp [filename on cluster] . For example, if I have a file called “myplot.jpg” in ~/probset1/ on updraft, I would type > scp [email protected]:probset1/myplot.jpg . The “scp” command treats everything after the colon as though it starts in your home directory on the cluster. It will copy the file to whatever directory you’re in on your local machine.

Note to all: gnuplot is an X11-based program. Mac users: Make sure that you connect to the clusters with the “ssh –X” command. The “-X” will allow all X11-based programs to pop up windows on your local machine. Try #4 below to confirm that this works. Windows users: This program is the first (and probably only) instance where you will need Xming. It should be running when you connect to the cluster. You will also have to enable X11 tunneling in SecureShell: 1. Connect to the cluster with the “quick connect” option. 2. Once connected, click ProfilesAdd Profile. Give it any name (probably Updraft or Ember), and click “Add to Profiles”. 3. Click ProfilesEdit Profiles. In the left panel, click on the name you just gave. In the “Connection” tab, type the address of the cluster (updraft.chpc.utah.edu or ember.chpc.utah.edu) in the “Host Name” box, and put your uNID in “User Name”. Then, in the “Tunneling” tab, check the box for “Tunnel X11 connections”. Click “OK”, close the program, and start it again. (Note: The program didn’t save my when I did this the first time. If this happens, just do #3 again.) To connect again, just go to Profiles[name you entered]. It should automatically ask for your password. 4. To if X11 is working, in the terminal window type “xterm”. A new terminal window should pop up that looks slightly different. If so, just close it…X11 works, and gnuplot should now work, too. If not, email me.