Chem 7520 Unix Crash Course Throughout This Page, the Command Prompt Will Be Signified by “>” at the Beginning of a Line

Chem 7520 Unix Crash Course Throughout This Page, the Command Prompt Will Be Signified by “>” at the Beginning of a Line

Chem 7520 Unix Crash Course Throughout this page, the command prompt will be signified by “>” at the beginning of a line (you do not type 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: > pwd 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: > ls You may see some file 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 “cd” 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 more detailed path names to navigate. Let’s say that I am in my qchem/ directory, but I want to switch to my chem7520 directory, which 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 “cp”, “mv”, and “rm”. 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’ed, 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 operating system 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 dot—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 > echo $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 $HOST Making directories Above, we established how to move between directories. You can create your own with the “mkdir” command. For example, to make 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 “vi”, 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 time, 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 most 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 graph 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.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us