Unix command line 101¶
The Hoffman2 Cluster is a Linux-based computing platform. One of the most powerful ways to interact with the Hoffman2 Cluster is via the Unix-command line. You can access the Hoffman2 command line by logging into the system either via a terminal application (see: Connecting-via-SSH) or by opening a remote desktop on Hoffman2 (see: Connecting via NX clients) and opening a terminal window. Any of these methods will open a command-line interpreter or unix shell (or most simply shell). This page presents a review of common tasks you may need to execute or script in your shell.
Environmental variables¶
On a unix-like system any string that is preceded by a $ is a
variable, which means that the operating system will interpret the
string according to what it has been set to. Environmental variables
are a set of variables that influences the behavior of the
command-line or shell interpreter in use (typically Bash). Example
of environmental variables that are set for you are:
$HOME
$SCRATCH
$PATH
$LD_LIBRARY_PATH
to check the content of a variable, for example $HOME, issue:
echo $HOME
the content of your $PATH and $LD_LIBRARAY_PATH influences the kind of executables and libraries that you can access at the command line (without specifying their full path).
Working with files¶
Unix-like systems have more than one way to display the content of a file, or selecgted snippet of it, on your unix shell. Among some of the most usefule commands are: cut, less, more, head and tail. To see how they work, issue at Hoffman2 command promt, for example:
cut $HOME/.bashrc
less $HOME/.bashrc
more $HOME/.bashrc
to exit from displaying a file with more or less issue:
q
To see just the first few lines of a file:
head $HOME/.bashrc
or, for the first two lines:
head -n 2 $HOME/.bashrc
to see the last few lines of a file:
tail $HOME/.bashrc
or, for the last two lines:
tail -n 2 $HOME/.bashrc
to look at the last few lines of a file that is being written on the fly:
tail -f /u/local/licenses/LOGS/logit.matlab
use:
Control-C (to exit)
Unix-like system have very powerful editors packed with shortcuts that
largely simplify the editing task. The learning curve on some of these
editors, such as vi, can be pretty steep. However, there are
several simpler, if less powerful, alternatives.
Editors that do not require X11 Forwarding¶
Here are some of the file editors available on the Hoffman2 Cluster presented in order of the complexity of their use, from less to more complex:
nano
emacs
vi
Editors that require X11 Forwarding¶
Here are some of the file editors available on the Hoffman2 Cluster when X11 Forwarding is enabled (see: Connecting via NX clients) presented in order of the complexity of their use, from less to more complex:
nano
gedit &
emacs &
vi
gvim &
Miscellaneous commands¶
Most unix commands have manual pages that can be accessed via the man command, for example to learn more about the ls command, issue:
man ls
or:
man vi