Customizing the Command Line
Everything on this page is optional. Skip it on a first read and come back once the basics feel comfortable — but these are the changes that turn the command line from something you tolerate into something you like.
Your Startup File
Every time you open a terminal, the shell reads ~/.bashrc and runs
whatever is in it. That file is where your customizations go.
The quickest way to see what that means is to put something harmless in it.
1. Open the file.
[scc4]$ gedit ~/.bashrc &
2. Add this line at the bottom, then save and close the editor.
echo "hello world"
3. Open a new terminal.
hello world
[scc4]$
Your greeting is printed before you get a prompt. Every line in ~/.bashrc
runs that way — once, at the top of every terminal you open — which is why
an alias or a umask written there is in effect from the moment you sit
down.
You do not have to open a new terminal for every change, though. source
re-reads the file in the terminal you are already in:
[scc4]$ source ~/.bashrc
4. Take the line out again.
It has done its job, and a ~/.bashrc that prints things is not purely
harmless: some programs connect to the SCC expecting nothing but their own
data on the line, and unexpected output confuses them. Delete the echo,
save, and open one more terminal to confirm the greeting is gone.
Aliases
An alias is a short name for a longer command. Each one is a single line in
~/.bashrc, and they are independent of each other — take the ones you
want and leave the rest.
ll — a readable directory listing.
alias ll='ls -lh'
-l puts one file per line with its permissions and size, and -h prints
those sizes as 4.0K and 51M rather than as raw bytes.
proj — jump straight to your project directory.
alias proj='cd /projectnb/your_project'
Saves retyping the full path every time you open a terminal.
rm — ask before deleting.
alias rm='rm -i'
An alias can reuse the name of the command it wraps. rm -i asks for
confirmation on each file, which turns the least forgiving command on the
system into one that checks with you first — see the warning on
The Linux Command Line.
qstat — show only your own jobs.
alias qstat='qstat -u your_username'
The same trick again. Plain qstat lists every job on the cluster, which is
almost never what you wanted.
fscheck — open a FreeSurfer subject for a quality check.
alias fscheck="freeview -v mri/wm.mgz mri/brainmask.mgz -f surf/lh.white:edgecolor=blue surf/lh.pial:edgecolor=yellow surf/rh.white:edgecolor=blue surf/rh.pial:edgecolor=yellow"
Opens the volumes and surfaces with the overlays and edge colors you want for checking a reconstruction. Run it from inside the subject's directory. Nobody is typing that from memory twice.
Default Permissions for New Files
Every file you create starts with a default set of permissions, and umask
is what decides them. It is a mask: the digits say which permissions to
withhold.
[scc4]$ umask
0022
0022 withholds write permission from your group and from everyone else, so
a file you create comes out looking like this:
-rw-r--r--
You can read and write it; everyone else can only read it. That is sensible when you work alone, and inconvenient on a shared project — a collaborator can open your files but cannot change them.
Setting the mask to 002 withholds write permission only from other,
leaving your project group able to edit:
[scc4]$ umask 002
A new file then comes out as -rw-rw-r-- and a new directory as
drwxrwxr-x. Put the line in ~/.bashrc to make it the default in every
session.
umaskonly affects files created afterwards. Files that already exist keep the permissions they were made with; change those withchmod, covered on The Linux File System.
Loading Modules Automatically
You can put a module load line in ~/.bashrc so a package is simply there
in every terminal, without your having to think about it:
module load fsl/6.0.7.8
Do this sparingly. ~/.bashrc is read by every shell you start, and
that is more places than it first appears — including the shells SCC
OnDemand uses to launch interactive apps. A module that changes where the
system looks for programs and libraries can stop a Desktop, Jupyter or
RStudio session from starting at all, and the error you get back will not
mention ~/.bashrc.
FSL is a fair example of one to be careful with: along with its own commands it brings its own Python and graphics libraries, which can shadow the ones an OnDemand app expects to find.
The safer habit is to load modules where you use them — in the terminal when
you sit down to work, and in the job script for anything you submit. A batch
job does not inherit what you loaded in your terminal anyway, so the
module load line has to be in the script regardless (see
The Batch System), and naming the version there is what keeps
the job reproducible months later.
If an OnDemand app stops launching, comment out any
module loadlines in~/.bashrcand try again before you go looking anywhere else.
A More Useful Prompt
The default prompt shows only the name of the directory you are in, not the path to it:
[janedoe@scc4 janedoe]$
Once you are a few levels deep that stops being useful — two directories
called janedoe in different parts of the tree look identical. The variable
PS1 controls the prompt, and \w swaps the bare name for the whole path:
PS1='[\u@\h \w]\$ ';
which gives you:
[janedoe@scc4 /projectnb/tutorial/students/janedoe]$
If you would rather have some color, and the path on a line of its own so long commands have room:
PS1=' \[\033[0;36m\]\u\[\033[0;95m\]@\h:\w\n[\!]\[\033[0m\]';
which gives you the username in cyan, the host and path in magenta, and the command's history number underneath:
janedoe@scc4:/projectnb/tutorial/students/janedoe
[42]
Put whichever you prefer in ~/.bashrc.
Those backslash codes each stand for something — \u for your username,
\w for the working directory, and so on. If you want to build a prompt of
your own, the full list is in the Bash manual under
Controlling the Prompt.
Further Reading
- Configuring your environment — the RCS page on setting up your SCC environment.
- Controlling the Prompt
— the full list of
PS1codes, in the Bash manual.