This is an old revision of the document!
BASH Customisation
The standard BASH colour configuration uses a blue colour for listing directories (ls) which is difficult to read on a black background. While this is the “standard colour”, due to the impracticality I have decided to change it.
The personal BASH user configuration file is: ~/.bashrc
. Simply add the following line to this file: LS_COLORS='di=1;32' ; export LS_COLORS
The code 1;32; is for a light green colour.
The .bashrc
file also has a number of other interesting “features” and options, such as aliases and colour prompts. If you turn on the colour prompt option (force_color_prompt=yes), again the dark blue colour may be difficult to read so I change the prompt color code from 34 to 36.
To update the terminal, without logging off type: ~/.bashrc
or source ~/.bashrc
. The command exec bash
will also work.
Add the following commands to vim ~/.bashrc
, the aliases can also be added to the separate file .bash_aliases, vim ~/.bash_aliases
:
alias ll='ls -la --color=auto'
alias lh='ls -laL --color=auto'
- key
ls
options :-a
,--all
: do not ignore entries starting with . (do not ignore hidden files)-l
: use a long listing format-L
,--dereference
: when showing file information for a symbolic link, show information for the file the link references rather than for the link itself-h
: use binary abbreviation (e.g. 1k 10G 2T, etc.)-i
: show index number of each file-R
: list sub-directories recursively-S
: sort by file size, largest first-t
: sort by time
To allow the BASH history to be updated from each terminal after each command, instead of last closed bash terminal overwriting others upon closure add:
export HISTTIMEFORMAT="%d/%m/%y %T " export HISTCONTROL=ignoredups:erasedups # no duplicate entries export HISTSIZE=100000 # big big history export HISTFILESIZE=100000 # big big history shopt -s histappend PROMPT_COMMAND="history -w" export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
To reload bash: exec bash
The following command gives an example of time format control on ls command. ls -l --time-style="+%Y-%m-%d %H:%M:%S"
BASH History Customisation and Use
- history | grep command → to see list of history with text “command”
- history !x → to repeat the history command at line x
- history -d x → to delete history line x
Links:
- danyspin97's site Colorize your CLI
- shopt The Shopt Builtin] sh options, simply type ''shopt'' to see list with current settings. Looks like built ins only? * set [[https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html|The Set Builtin set options,
set
on its own list entire content. (Looks like user defined?)
exa
A modern replacement for ls. I tried it and could not be bothered with it and uninstalled.
grc
General colouriser. I installed it but do not bother to use it normally.
ble.sh
ble is a tool for bash that add command line continuation and colouring as well as other features.
Like it and use it
BASH Prompt
I like a standard looking prompt, none of these Apple look alike things that seem to be popular on the nerd media at the moment. I do not see much value in the prompt showing the date as this is shown on the main GUI screen.
References
Colors
Seems like the main terminal colors is 1bit (light and dark), 4 bit or 16 colors, while “expanded” is 256 colors. The pallet the colors can be selected from can be varied from 24bits (16M) on more modern systems. The LS command allows the colors to be changed via the LS_COLOR environment variable. Similarly programs like vim allow its colors to be varied. The terminal programs can have their colors adjusted there. I problem I encounter was the dark blue on black background was illegible. Changing the dark blue to a lighter blue resolved this issue. I also changed the white to yellow so the text is more appealing to read, at least for me.
Some interesting references on this are:
- How to change the color of your Linux terminal Make Linux as colorful (or as monochromatic) as you want.
- ShellHacks Bash Colors
visudo
sudo remembers your password for 15 minutes by default. After 15 minutes, you will be asked to enter the password again for any sudo command.
This is actually a security feature. For instance, if you left the terminal open after running commands with sudo, the authentication automatically expires after 15 minutes of sudo inactivity. So, the other users can’t do any further administrative tasks.
This behaviour can be changed by increasing or decreasing the sudo password timeout limit as described below.
sudo visudo
Find Defaults env_reset
and change to Defaults env_reset, timestamp_timeout=30
This will change the default 15 minutes time out to 30 minutes. Changing the timestamp_timeout=0 will require the sudo password at every use. Specifying a negative value and the timeout will never expire.
sudo -k
resets the sudo timeout and password must be entered again next time sudo is used.
The default timeout seems pretty reasonable to me so I can not be bothered changing it!
Change Sudo Password Timeout in Linux
Display Brightness Control
Strangely XFCE does not seem have and any kind of screen brightness control built in. There also seems to be no optional extra for this either.
Bash: A Simple Script for Changing Display Brightness with XRANDR
xrandr --listactivemonitors
to list current active monitorsxrandr --output HDMI-1 --brightness 0.5 && xrandr --output DP-2 --brightness 0.5
xrandr --output [displayID] --gamma 1.0:0.95:0.85
to give a night mode effectxrandr --output HDMI-1 --gamma 1.0:0.9:0.85 --brightness 0.7
to give a combined night and dimming effect.
Archive
tar
tar
comes from tape archive. I was original a program to store and retrieve information to tape backup system. Basic tar functionality did not originally include compression, but this was added later.
create
main tar
create options, e.g.: tar -cvf archive_filename.tar file1 directory1 file2
-c
: for create archive, a pretty self-explanatory option if you want to create a new archive made from the files selected;-v
: for verbose, this is the reason why the command displays the files added to the archive when executing it;-f
: for file, this option is used in order to specify the filename of the archive we want to create (in this case archive.tar)
extract
tar -xvf archive_filename.tar
-x
: for extract archive, a pretty self-explanatory option if you want to extract information from an archive.
list contents
tar -tvf 'archive filename
'
compression
Use either gzip
, bzip2
, or xz
to directly compress a file
gzip
, extension.gz
, withtar
use flag-z
bzip2
, extension.bz2
, withtar
use flag-j
xz
, extension.xz
, withtar
use flag-J