Tips and tricks - uic-ric/uic-ric.github.io GitHub Wiki
The following are a set of "tips" and "tricks" that ight make it easier to use the various Bioinformatics resources, e.g. Linux/HPC or R.
Using this setup, BASH will create a separate history file each time you login. This will allow you to look back at your command history for any previous login session. Furthermore, the history files will not be truncated, deleted, or overwritten by BASH.
- Create a
.history
directory in your home directory
[user@login-1 ~]$ mkdir -m 700 .history
- Add the following to your
.bash_profile
export HISTFILE=${HOME}/.history/histfile.$(date +'%m.%d.%Y').$(hostname).$$
You will need to logout and login again for the changes to take effect. The name of the history files will include the date as month.day.year, e.g. 01.30.2019
is Jan 30th, 2019, the hostname of the system, and the PID of the original BASH process, this is just required to create unique history files for each login session on the same day.
In BASH, the format of your command prompt is defined by the special variable PS1
.
- To set the prompt when you login to system, e.g. SSH into the Lakeshore head node, define PS1 in your
.bash_profile
file. - For other instances when BASH is run, e.g. you get an interactive node via SLURM, define PS1 in your
.bashrc
file.
There are a few special escape codes that will tell BASH to fill in the existing value of some parameter, e.g. current directory or hostname. A full list of possible escape codes that can be used in a BASH prompt is available at https://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html. The following are some of the most commonly used ones.
Escape code | Description |
---|---|
\H | Full hostname of the server. Example: login001-lakeshore.acer.uic.edu |
\h | Hostname of the server, up to the first period (.). Example: login001-lakeshore |
\W | Full path of the working directory. Example: /workshops/ric_workshops/common |
\w | Last part of the current working directory. Example: 2_LinuxHPC |
\u | Your login ID. Example: gchlip2 |
All other characters in the PS1
value will be printed as is. For example, the following PS1
value...
export PS1="Lakeshore [\u@\h \W]\$ "
... would result in the following prompt
If you wanted to create a slightly different prompt for interactive SLURM sessions, you can define a different value of PS1
in your .bashrc
file and have our main login prompt defined in the .bash_profile
.
For example, we could define the following in .bashrc
that would appear in interactive SLURM sessions.
export PS1="SLURM \h:\W\$ "
The following examples use ANSI colors (https://gist.github.com/JBlond/2fea43a3049b38287e5e9cefc87b2124) codes that allow a terminal to display text with different colors. Granted, this depend on if your computers Terminal application or SSH client supports ANSI colors.
To reference the particular color codes in the PS1
variable, you will need to wrap the color code with \[\033[
and \]
. For example, the color code for blue text is 0;34m
. So, to start writing text in blue add \[\033[0;34m\]
at the start of the text. Then add \[\033[0m\]
to clear out any color codes and go back to normal text. If you wanted to print Lakeshore in blue text you can use "\[\033[0;34m\]Lakeshore\[\033[0m\]
"
For example, here is the previous Lakeshore prompt with the word Lakeshore in bold blue (1;34m
) and the path displayed in cyan (0;36m
).
export PS1="\[\033[1;34m\]Lakeshore\[\033[0m\] [\u@\h \[\033[0;36m\]\W\[\033[0m\]]\$ "
Here is the previous SLURM prompt with the background in blue (44m
) with the word "SLURM" in bold (1;44m
) and the rest of the text in regular weight (0;44m
) and the path in cyan (0;36m
).
export PS1="\[\033[1;44m\]SLURM\[\033[0;44m\] \h\[\033[0m\]:\[\033[0;36m\]\W\[\033[0m\]\$ "