Introduction
Some Linux terminals especially remote ones look lifeless. In this post I want to show in 10 min, how hugely you can improve interaction experience with those terminals by using aliases, customising command prompt and ls
output, and adding history date.
Prerequistis
I am assuming you are familiar with Bash terminal and its commands and bashrc and bash_profile.
Alias
This one is top priority: define as many as aliases that saves your time in typing. There are many long commands that you type many times a day, make aliases for them like:
alias workssh="ssh myid@blah.blah.blah"
alias hgrep="history | grep"
alias current="cd '~/program1/bin/'"
Customise bash prompt
The default command prompt may look like this:
my-machine$
in plain white and not showing the current directory or any other information. To change that, we need to set PS1
environment variable. The coloring code can be really confusing, to save time we use this free online bash PS1 generator. In the website, drag and drop items such as date, directory, and hostname. By clicking on each item, you can set the color of them. This is what I made:
Now copy-paste the export PS1=blah blah blah
into your terminal. You should immidiately see the change. Also you can paste the line into ~/.bashrc
and ~/bash_profile
to make it as the default style.
Color ls output
ls
colors are set in the environment variable LS_COLORS
. You can check if it is set in your terminal by running
echo $LS_COLORS
The format of LS_COLORS
is like:
filetype1=x1;x2:filetype2=x3;x4;x5:...
where filetype1, 2,… are specific file extensions like *.jpg, *.png or the below table
filetype | explanation |
---|---|
NORMAL | Normal (nonfilename) text |
FILE | Regular file |
DIR | Directory |
LINK | Symbolic link |
EXEC | Executable file |
x1, x2,… are the codes which are picked from the table below
FG=foreground
BG=background
code | behavior |
---|---|
0 | default color |
1 | brighter colors |
4 | underlined text |
5 | flashing text |
30 | for black FG |
31 | red FG |
32 | green FG |
33 | yellow (or brown) FG |
34 | blue FG |
35 | purple FG |
36 | cyan FG |
37 | white (or gray) FG |
40 | black BG |
41 | red BG |
42 | green BG |
43 | yellow (or brown) BG |
44 | blue BG |
45 | purple BG |
46 | cyan BG |
47 | white (or gray) BG |
This is the LS_COLORS
I have in ~/.bashrc
of a remote server:
export LS_COLORS="di=4;44:*.pbs=0;33:*.txt=0;34:*.vtk=0;36:*.vti=0;36:*.cpp=0;32:*.cmake=0;31:*.stl=0;35:*.py=0;32;47:*.csv=0;37;44:$LS_COLORS"
Running ls
in a folder I get:
If you don’t see any color, there is a chance that coloring is off, add this into ~/.bashrc
and/or ~/.bash_profile
.
alias ls="ls --color=auto"
History date
As far as I’ve seen, bash history doesn’t store time and date of previous commands. To do so, add this to your ~/.bashrc
and ~/.bash_profile
:
export HISTTIMEFORMAT="%d/%m/%y %T "
There has been times, I really needed the exact time that I deleted something and this helped me.
More like this
See this post that I show how you can systematically copy current path in a Shell terminal and use it somewhere else.
References
Latest Posts
- A C++ MPI code for 2D unstructured halo exchange
- Essential bash customizations: prompt, ls, aliases, and history date
- Script to copy a directory path in memory in Bash terminal
- What is the difference between .bashrc, .bash_profile, and .profile?
- A C++ MPI code for 2D arbitrary-thickness halo exchange with sparse blocks