Table of Contents

Useful Linux Commands

The following will help you get started with Linux on the SCS Network. It will only describe the very basics. For an in-depth look at Linux, the internal workings, and how the operating system works see the O'Reilly set of books in particular 'Essential System Administration' by Aeleen Frisch.

A lot of the content has not yet been moved to the new support site. For more information, please visit the old linux help page.

Opening a Terminal Window

Linux has a window manager, and windows that you can work with. (SCS uses Gnome as the default window manager). Although GUIs are useful, and many tasks can now be done using GUIs, much of the work in Linux is still done on the command line. Essentially all work can be done on the command line, without using the GUI at all. The terminal window is used to type command line arguments. For the Gnome window manager you have to access the menu (top left corner icon) and then select “Accessories → Terminal”.

Basic Linux Commands

When using a Linux command line, the following commands are essential to navigating around the system:

Linux Command DOS Command Description
ls dir List the files in a directory.
Usage: ‘ls’ or ‘ls directory
cd cd Change to a different directory.
Usage: ‘cd directory
Some special examples are ‘cd ..’ which moves up one directory, or ‘cd ~’ which switches to your user home directory.
rm del, deltree Delete files or directories.
Usage: ‘rm file’ or ‘rm -r directory
cat type Display the contents of a file.
Usage: ‘cat file
clear cls Clear the screen.
Usage: ‘clear
mkdir mkdir Create a new directory.
Usage: ‘mkdir directory
cp copy Copies files or directories.
Usage: ‘cp file destination’ or ‘cp -R directory destination
mv ren, move Move or rename files or directories.
Usage: ‘mv file destination
find Locate files within a directory.
Usage: ‘find directory -name file
Example: ‘find ~ -name '*.c'’ will find all of the C source code files in your home directory.
tail Display the last few lines of a file.
Usage: ‘tail -n lines file
Example: ‘tail -n 20 project.c’ will display the last 20 lines of the source code in project.c.

For more help with Linux commands, you can use the built-in help system. Type ‘man command’ to see the help page for a particular command. In addition, you can read the online unix help.

Linux Command-Line Examples

Here are some examples of more complicated commands which you may find useful.

Linux Command Description
less README.txt
Display the file README.txt on the screen, allowing you to scroll through it with arrow keys. Press ‘Q’ to exit.
date > date.txt
Get the current system date and time, and save the output to the text file date.txt
grep keyword README.txt
Search the file README.txt for keyword, and display any matching lines.
uname -a
Display the version of the operating system which you are using.
tar -acvf archive.tar.gz project/
Create a compressed archive of a directory, much like a zip file.
tar -xvf archive.tar.gz
Extract a compressed archive to the current directory.
whoami
Display the name of the user that you are currently logged in as.
ssh lambda02
Use a secure, encrypted protocol to log into a different computer. You will get a command prompt on the remote computer. You can use exit to return to your original computer.

Linux Text Editors

Linux has two different types of editors; command line editors and gui-style editors. Command line editors are useful because they are fast and they can be run from an xterm window. Two command line editors that you can find on Linux systems are “nano” and “vi”.

Nano is a very easy to use and simple text editor. You can use arrow keys to move around within a file, and a list of all the commands that you can use is printed at the bottom of the screen. For example, “^X Exit” means that if you type Ctrl-X, the editor will exit.

The popular vi editor is an old editor which is very powerful, but more difficult to use. It is known as a “modal” editor, because it has two modes. In Normal mode, typing runs different editing commands. Some commands, such as “i” switch to Insert mode, where you can type text in the file. Pressing “Escape” returns to Normal mode. In addition to the old “vi” editor, there is an updated version called “vim” which is installed on many systems.

A summary of commonly used vi commands is presented here. In many versions of vi, you can type “:help” to see a help screen. In addition, on systems with vim, you can run the “vimtutor” command on the command line to run through a tutorial designed to teach the basics of vi.

Command Description
i Insert. This changes the editor mode so you can start typing text at the position where the cursor is located.
<Esc> Exits insert mode, so you can type editor commands.
a Append. Changes the editor to insertion mode, but you start typing after the current character instead of before.
x Delete a single character located under the cursor.
dd Delete the entire line that the cursor is on.
nG Jump to line n in the file that you are editing.
Ctrl-F Go forward one page.
Ctrl-B Go backwards one page.
u Undo the latest change made to the file.
/keyword Search for keyword in the file.
:q Quit the vi editor.
:w Save the changes made to the file you are editing.
:q! Quit the vi editor, discarding any changes you have made.

There are many GUI Linux text editors available, which can be easier to use. Gnome includes an advanced text editor called “gedit” which can be found in the Applications menu under “Accessories → Text Editor”.

If you are looking for a word processor, like Microsoft Word, try “Open Office”, which will be located in the “Office” section of the menu.

SSH Without a Password

Sometimes you may want to be able to ssh (secure-shell) between linux hosts without typing your password. This can be useful when doing some sort of parallel programming, using lam or mpi, or just for convenience. Instead of entering a password, SSH can authenticate you using high-strength encryption keys.

To set up passwordless ssh between SCS Linux hosts, run these commands:

ssh-keygen

The command will prompt you for a filename. Press Enter to accept the default id_rsa. You will also be prompted for a passphrase. For passwordless ssh, press Enter without entering a passphrase.

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

This tells ssh that the key which was just generated has permission to access this computer. As all of the SCS network computers share the same home directory using NFS network mounts, this permission will be granted on all SCS computers.

If your account is not NFS mounted you must scp (or copy) the ~/.ssh/authorized_keys file to the destination host and account.

You must now log into every SCS linux machine at least once to initialize the encryption key per host. After you logged in once you should be able to ssh to the host without typing your password.