Basic Unix Command-line Tools

 

Many of the exercises in this course require you to interact with a Unix system (e.g. harris.sas.upenn.edu) via command line tools in a terminal window. As we go through the course, we'll introduce and explain other tools, but there are a a dozen basic commands that you should learn to start with, if you don't already know them.

To start with, you need to get access to a terminal. On a linux machine, xterm and other terminal programs are basic and will always be there. On a Windows machine, you should be able to install WSL for a basic unix environment. In MacOS, there's a terminal program in the /Applications/Utilities folder. On a Mac, you might also want to install Xcode, if you haven't already done so.

In any terminal window, you'll see a prompt followed by a cursor, something like this (where a red arrow has been added to the diagram to indicate the cursor location):

Whatever you type appears at the cursor location.

One thing you'll want to do is to login in remotely to harris.sas.upenn.edu. If you have an account there, this is easy -- just type at the prompt

$ ssh harris.sas.upenn.edu

and it'll happen -- harris will type some stuff back at you, and then give you its own prompt:

[Note that if you're not within Penn's intranet, you'll need to install and run GlobalProtect, using the portal vpn.upenn.edu.]

[Also note that if your userid on your local machine is not your PennKey, you'll need to login via

$ ssh xyz@harris.sas.upenn.edu

where your Penn email address is xyz@upenn.edu.

In addition to ssh, here are some other commands you should be familiar with:

man: "man X" will give you the manual page for X.

pwd: = "Print Working Directory" -- tells you where you are in the directory hierarchy. Usually this will also be indicated in your prompt.

cd: "cd /plab/L521" will change the current working directory to /plab/L521 (or whatever other directory you specify). Note that directories can be specified via an absolute pathname (one that start with the root "/") or a relative pathname.

ls: = "List" the files and directories in the current working directory. Or you can specify a pathname, e.g.

myl@harris:~$ ls /plab/bu_radio
data docs

less FILE: = "show the start of FILE, as much as will fit in the terminal window". You can page through the rest of the file using the space bar.

For the following commands, you can use "man" to find out what they do. (And you can do the same for the six commands listed above.) Generally there is a complicated set of flags and other arguments to modify the command's behavior -- usually you don't need to learn very many of these, if any at all.

file = "describe the type of a file"
cp = "make a copy of a file or directory"
mv = "rename a file or directory, i.e. move it"
soxi = "describe the format and content of an audio file"
mkdir = "make a new directory"
rm = "remove a file"
scp = "secure copy" -- copy files to and from remote machines

For more, there are many online tutorials...

Choosing and learning a plain-text editor

You'll often need to use a plain-text editor in order to create or modify script,notes or whatever.

You could use Notepad on your Windows machine, or TextEdit on a MacOS machine, and copy files back and forth to harris or wherever. But at some point you should learn to use a native solution: vim, emacs, nano, whatever. (All three of those are installed on harris -- and can also be used on your Mac or Windows laptop.)

Graphics across machines

The X Window System is a windowing system for bitmap displays, whose most relevant feature is that it allows remote graphical user interfaces and input devices. In other words, you can run a program (a WYSIWYG editor, a statistics and graphics system, etc.) on one machine, but have the display (and keyboard and mouse inputs) on another. This will be convenient, for example, as a way to edit a file on harris.sas.upenn.edu, without having to copy it back and forth to your own machine.

In order to use a local X server with a program on a remote machine, you'll need to ensure that X packets are forwarded. If you're using ssh, you can add the -Y flag, e.g.

      ssh -Y harris.sas.upenn.edu