Prev  
 Next

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 -lah --time-style=long-iso --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
    • --time-style : allows the displayed time sytle to be changed.
      • The standard output is a disgrace, North American mixed up! Aug 23 2022 or Jan 1 11:44 for nearer dates.
    • iso gives 2023-01-23 for more than a year past and 10-23 15:51 for less than a few months past, yuk!
      • long-iso always gives yyyy-mm-dd hh:mm, without a doubt the best format, clean and consistant!
      • full-iso is same as long-iso, except time time is to the nanosecond and local timezone delta is displayed
      • The TIME_STYLE environment variable sets the default

An example alias file:

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"

  • 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:

bash configuration utilities I have not tried yet. References:

A modern replacement for ls. I tried it and could not be bothered with it and uninstalled.

General colouriser. I installed it but do not bother to use it normally.

ble.sh is a tool for bash that add command line continuation and colouring as well as other features.

blesh seems to swamp the set variables. Pipe to less as the list is so long I it fill my terminal buffer on straight output.

Like it and use it

Reference:

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

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:

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


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 monitors
  • xrandr --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 effect
  • xrandr --output HDMI-1 --gamma 1.0:0.9:0.85 --brightness 0.7to give a combined night and dimming effect.

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.

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)

tar -xvf archive_filename.tar

  • -x : for extract archive, a pretty self-explanatory option if you want to extract information from an archive.

tar -tvf 'archive filename'

ps aux to see current process

killall name pkill name pkill -9 name

Use either gzip, bzip2, or xz to directly compress a file

  • gzip, extension .gz, with tar use flag -z
  • bzip2, extension .bz2, with tar use flag -j
  • xz, extension .xz, with tar use flag -J

Use sudo update-alternatives –config editor and follow prompts on screen

Reference:

  • /app/www/public/data/pages/home_server/home_server_setup/other_services/bash.txt
  • Last modified: 2024-01-02 Tue wk01 21:44
  • by baumkp