GNU/Linux Shell Basic Shell Utilities


Customizing the Shell prompt

Default command prompt can be changed to look different and short. In case the current directory is long default command prompt becomes too large. Using PS1 becomes useful in these cases. A short and customized command pretty and elegant. In the table below PS1 has been used with a number of arguments to show different forms of shell prompts. Default command prompt looks something like this: user@host ~ $ in my case it looks like this: bruce@gotham ~ $. It can changed as per the table below:

PS1='\w $ '~ $ shell prompt as directory name. In this case root directory is Root.
PS1='\h $ 'gotham $ shell prompt as hostname
PS1='\u $ 'bruce $ shell prompt as username
PS1='\t $ '22:37:31 $ shell prompt in 24 hour format
PS1='@ $ '10:37 PM shell prompt in 12 hour time format
PS1='! $ '732 will show the history number of command in place of shell prompt
PS1='dude $ 'dude $ will show the shell prompt the way you like

Some basic shell commands

Ctrl-awill take cursor to the start of the line
Ctrl-ewill take cursor to the end of the line
Ctrl-dwill delete the character after/at the cursor
Ctrl-lwill clear the screen/terminal
Ctrl-uwill clear everything between prompt and the cursor
Ctrl-_will undo the last thing typed on the command line
Ctrl-cwill interrupt/stop the job/process running in the foreground
Ctrl-rreverse search in history
~/.bash_historystores last 500 commands/events used on the shell
historywill show the command history
history | grep <key-word> will show all the commands in history having keyword <key-word> (useful in cases when you remember part of the command used in the past)