The Linux Command Line

The terminal is where almost all SCC work happens. You type a command, press Enter, and the machine does something. That is the whole model.

Reading the Prompt

The text sitting to the left of your cursor tells you three things:

[janedoe@scc4 ~]$
Part Meaning
janedoe your username
scc4 the node you are on
~ the directory you are in; ~ is shorthand for your home directory

The $ marks the end of the prompt. Everything after it is what you type.

Examples on this page use janedoe as the username. Elsewhere in this guide the prompt is shortened to [scc4]$ to keep the lines readable. Your own prompt will show your username and whatever node you landed on.

The Anatomy of a Command

Everything you type after the $ follows the same pattern. Here is a command that lists what is inside a directory:

[janedoe@scc4 ~]$ ls -l /projectnb/tutorial/janedoe
total 50433
drwxr-sr-x 5 janedoe tutorial     4096 Mar 20 16:30 fmriprep
-rw-r--r-- 1 janedoe tutorial 51640320 Mar 21 10:31 fmriprep.tar

The command itself is made of three parts:

ls -l /projectnb/tutorial/janedoe
|  |  |
|  |  +-- input argument
|  +----- flag
+-------- command
Part What it is
ls The command. The action you want performed.
-l A flag. Flags start with - and change how the command behaves. They are almost always optional — plain ls still works, it just prints less.
/projectnb/tutorial/janedoe An input argument. The thing the command acts on.

The three lines underneath are the command's output. Not every command has any — cd does its job and prints nothing at all.

What the columns in that output mean is covered in The Linux File System.

Finding a Command's Options

-l is one of many flags ls accepts. To see the rest, ask the command itself with --help:

[janedoe@scc4 ~]$ ls --help | head
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      with -l, scale sizes by SIZE when printing them;

Almost every Linux command accepts --help. The | head on the end trims the result to the first ten lines — ls --help on its own prints far more than fits on a screen.

For the fuller manual, use man ls instead, and press q to leave it.

The Commands You Actually Need

Command Does Example
pwd print the current directory pwd
ls list a directory's contents ls -l
cd change directory cd /projectnb/your_project
mkdir make a directory mkdir nifti
cp copy a file cp data.nii backup.nii
mv move or rename mv test.sh run.sh
rm delete rm old.nii
cat print a file to the screen cat results.txt
less page through a long file less notes.txt

That is the short list. RCS publishes a fuller one: the SCC Linux Cheat Sheet (PDF) collects the most commonly used Linux commands on a single page.

rm does not ask and does not undo. There is no trash can on the SCC. A deleted file is gone unless it happens to be in a backed-up or snapshotted directory.

Two Shortcuts That Save Real Time

Tab completion. Type the first few characters of a path and press Tab; the shell fills in the rest.

[janedoe@scc4 ~]$ cp /project/scv/ex[Tab]/im[Tab]/tut_n[Tab]/tut[Tab] .

. means "here". A single dot is shorthand for the directory you are currently in, which is why the command above ends with one.

Getting Unstuck

Problem Try
A command is running and will not stop Ctrl+C
You are stuck in less press q
You do not know what a command does <command> --help, or man <command>

Further Reading