Example
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:
Command | Utility |
---|
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
Command | Utility |
---|
Ctrl-k | cut/kill |
Ctrl-y | yank/paste |
Ctrl-a | will take cursor to the start of the line |
Ctrl-e | will take cursor to the end of the line |
Ctrl-d | will delete the character after/at the cursor |
Ctrl-l | will clear the screen/terminal |
Ctrl-u | will clear everything between prompt and the cursor |
Ctrl-_ | will undo the last thing typed on the command line |
Ctrl-c | will interrupt/stop the job/process running in the foreground |
Ctrl-r | reverse search in history |
~/.bash_history | stores last 500 commands/events used on the shell |
history | will 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) |