New Mexico Tech
Earth and Environmental Science

ERTH 401 / GEOP 501 - Computational Methods & Tools

Lab 1: Exploring the command line & flow charts.

"Programming is legitimate and necessary academic endeavor."
Donald E. Knuth

Introduction

With this lab we're trying to introduce you to the command line, directories, etc. We're laying the foundation for the following labs. We can't possibly cover all commands / programs, etc. that you should know about. Below, we list a few resources. The google comment is a serious one! That's how you're likely going to be learning most of this!

Resources

Deliverables

Work through the ENTIRE LAB IN ONE TERMINAL SESSION then execute the following command (one line):

This sends an email to Sue, Zach, Ronni, and you (replace YOUREMAIL with, well, your email address) with the history of your terminal session. Make sure there are no spaces between the first 3 email addresses (space only before Zach's). You should check the email inbox that's linked to YOUREMAIL after you're done, to see what you sent to all of us. The vertical bar is called "pipe" which takes the output of one command and uses it as input for another. We'll talk about this later with UNIX tools, but this is a fairly intuitive application, I think.

IF YOU DON'T RECEIVE THE EMAIL YOU JUST SENT TO YOURSELF, COPY AND PASTE THE history OUTPUT INTO AN EMAIL AND SEND THAT TO ALL THREE OF US.

The second deliverable is the flow chart that you create in exercise III. Please send that in a separate email.

Exercise 0: Log-in

Find an open spot in MSEC 345 and log in with your E&ES credentials. If you end up with a Mac, the login process can take quite some time as your profile may need to be built if you log onto this machine for the first time (this will happen again if you switch to another machine).

Exercise I: Command line; Home Directory & Moving About

We'll do a lot of work on the command line. It's a non-graphical interface, which expects you to type text commands. Instead of clicking on an icon, you need to know the program name, type it in, hit enter and then something happens. Think green on black background and 80s Hacker movies! For instance $> firefox could start Firefox.

To get a terminal (there are several ways to get there):

on a Mac: open Finder -> Applications -> Utilities -> Terminal (you may want to pull the icon into your task bar, so it's readily available)

on Linux: Applications -> System Tools -> Terminal (you may want to pull the icon into your task bar, so it's readily available)

At this stage things between Mac and Linux are mostly the same. You're likely to see a window that has a white background with black text that says something like this:

        Last login: Sun Aug 20 12:37:22 2017
        [hydrosphere:~] grapenthin%
    

Here, hydrosphere is the name of the machine, I used and ~ signals that I am in my home directory. That brings us to an important point: directories and how to move about. You may call them folders, directories or something else. It's where files live. You're probably accustomed to navigate through directory trees using a graphical interface such as Finder, Windows Explorer or whatever else it may be. Let's play with this a bit:

This is a good point to insert an important note: There's no trash can on the command line. If you delete a file/directory on the command line, it's gone forever (let's just make that assumption and not talk about possible exceptions.) Poof! Gone! You might as well think of every file you delete on the command line as your thesis document! Be careful with this command. If you're lucky, there are backups (we have them here), better yet, regularly make your own backups!

There's a useful command that will help you in such situations: man. To figure out what this does > man man. (It doesn't have anything to do with men.) The man-pages are useful, but maybe not always easy to understand (you exit them by hitting q). Now, read the man-page of rm and figure out how to get rid of this directory. Note that square-brackets [...] enclose optional parameters; don't type these! You'll need to add a command line parameter, which is often a single letter preceded by a single dash/minus or a more comprehensible word preceded by two minuses. E.g.:

        $> man -h 
        $> rm --help
    

These are the standard ways how most programs offer a short help to you. Some offer both -h and --help, or just one of the two (for instance, rm only provides --help although other options are available as -...).

While we're at it: something else that's really useful, and frankly drives me nuts when someone doesn't utilize it on the command line is tab-completion. Read about it here.

Interlude for Linux: Python Virtual Environment Setup

If you logged onto a linux machine, follow the ITC instructions to setup a virtual environment for Python 2.7.

Exercise II: Moving About A Lot More: ssh

Type > hostname This tells you the name of the machine you're currently on. From my example above:

    [hydrosphere:~] grapenthin% hostname
    hydrosphere.ees.nmt.edu
    
You can quite easily log onto another machine without physically going there. For this we use ssh, a remote login program (man ssh). What you need for this is the name of the machine (e.g., hydrosphere) and the subdomain (e.g., ees -machine may not be on a subdomain) and the domain (nmt.edu) of the machine. Let's do this with an example.

    [grapenthin@cocos ~]$ ssh -X grapenthin@gorda.ees.nmt.edu
    The authenticity of host 'gorda.ees.nmt.edu (129.138.56.170)' can't be established.
    RSA key fingerprint is 89:89:8d:dd:1f:b4:bd:bf:d5:6f:cc:b6:d3:d3:36:d3.
    Are you sure you want to continue connecting (yes/no)?
    

I am trying to log user grapenthin into gorda; one of the linux machines. Here you can usually omit the username and @; as your user name is the same across the network. However, sometimes you're logging into machines as a different user. That's how. I am using the parameter -X to enable X-windows forwarding. This allows me to start graphical interfaces remotely, say firefox, and see the display on my local machine. This is sometimes quite useful, but can be really slow! My local machine talks about authenticity of the machine cannot be established and asks me to add the key fingerprint to the local hosts file and to continue. You have to type yes. The full word. And hit enter.

    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'gorda.ees.nmt.edu,129.138.56.170' (RSA) to the list of known hosts.
    grapenthin@gorda.ees.nmt.edu's password: 
    

And then you type in your EES password - note that nothing you type here will show up on the screen. You will end up with a new prompt:

    [grapenthin@gorda ~]$     
    

And hostname now gives a different result:

    [grapenthin@gorda ~]$ hostname
    gorda
    

Wanna know who else is on this machine?

    [grapenthin@gorda ~]$ who
    grapenthin pts/0        2017-08-20 14:33 (cocos.ees.nmt.edu)
    

Just me right now and I am visiting from cocos. Side note: you could now log into a different machine from here, and another, and another. Hackers like to make use of this, assuming a different user on each machine, to obscure where they actually came from.

Cool. You're in your home directory and should be able to see the same files as before: > ls

How do your terminate the connection? You type exit

    [grapenthin@gorda ~]$ exit
    logout
    Connection to gorda.ees.nmt.edu closed.
    [grapenthin@cocos ~]$ 
    

if gorda does not work, use hydrospherer or cascadia or glacier

You can have several terminals open, each logged into a different machine and run computationally intensive tasks on each of these.

This concludes the first part of this lab - you should execute the history command now and see what it prints. Then use the command given above to send the email containing this output to yourself and us as your first deliverable.

Exercise III: Drawing flow charts

Think of your project for the class (if you can't yet - then the path to a successful career in your field of study), identify manageable sub-tasks and link them together in a meaningful way. Visualize this in the form of a flow chart. We recommend to hand draw this as that's faster, things change a lot and it doesn't need to be pretty. Just deliver something that's legible and easy to follow (pre-defined flow chart symbols, give definitions for other symbols). Snap a photo, or scan the result and email to Sue, Ronni, Zach.

rg <at> nmt <dot> edu | Last modified: August 21 2017 21:38.