Trick out your Terminal

Terminal-icon-shell-linux-unixHere are some useful ways to enhance your operating system shell environment.  The first will give you a permanent bash history that’s up to date and doesn’t require a logout to update command history, nor does it get reset.  The second are some PS1 enhancement examples that have been useful to me.  This should work on both Linux or OSX, and is aimed towards the Bash shell –  let’s get started.

Bash Eternal History

The history command is very useful, it gives you a nice narrative on commands entered in your shell however it’s fairly limited in that saving history is only committed once your TTY exits.  Also history functionality has a limited size.

You can increase the history size (and filesize) via a ~/.bashrc variable however:

export HISTSIZE=10000000
export HISTFILESIZE=10000000

Keep it Permanently
I use the these lines in my ~/.bashrc to keep a permanent copy of all the commands run on my system along with increasing the histfilesize and histsize variable above.

               "$(history 1)" >> ~/.bash_eternal_history'

Now every command you type everywhere as your user is recorded.  As you can see I’ve had mine a while.

ls -lah .bash_eternal_history 
-rw-r--r--. 1 wfoster wfoster 4.5M Mar  8 18:14 .bash_eternal_history

Customize your Shell
You can also take advantage of shell PS1 variables, the customization I use shows current working directory and time and adds some additional color.  Experiment and find something you like.

export TERM="xterm-color"
export PS1="${C2}(${C1}\u${C2}@${C4}\h${C2}) - (${C4}\A${C2}) - (${C4}\w${C2})\n${C2}-${C1}=>>${C3}"

Before Settings:


After Settings:


What kind of customizations do you use in your shell environment?  If you have any tips or suggestions or find these tips useful leave a comment below.

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , . Bookmark the permalink.

1 Response to Trick out your Terminal

  1. John Florian says:

    Clever trick on the eternal bash history. I’ve had a hack I’ve used for years that never quite worked and I never quite had the time to fix it. Now I don’t have to. :-)

    Liked by 1 person

Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.