BASH in linux shell

BASH is the default shell in most of the Linux operating systems. To launch new shell terminal in Ubuntu, you can use CTRL+ALT+T hotkey. You can SHIFT+CTRL+N to create a new terminal window. You can use SHIFT+CTRL+N hotkey to start new terminal tab within existing window. You can check what shell you are running by using below command.
echo $SHELL

If you see the output as /bin/bash, it means that you are using the BASH Shell. To find out all commands starting with specific letter or letters, you can type the letter and press the TAB key twice. Also you do not need to enter the full directory or file name. You can type first few characters of the file and then press tab key. BASH will auto complete the file name automatically provided it is able to identify the file uniquely. For example – let us say we have 2 directories with name bigcities and bigcountries. Then to change the directory to bigcities, you can use below command.
cd bigc

and then press TAB key. Directory name will be auto-completed. But if type only “big” and then press TAB key, name will not be auto-completed because BASH does not find the unique directory name. To exit the shell you can use below command
$ exit

You must know below things when working with BASH.
  • CTRL+c – This hotkey sends SIGINT singal (Interrupt signal) to the application. It is up to the application if it has to terminate itself.
  • CTRL+z – This hotkey sends SIGTSTP singal (Stop signal) to the foreground application. Application is sent to the background in suspended mode.
  • You can view all application that are in background using jobs command.
  • CTRL+a – sends the cursor to the start of the command line.
  • CTRL+e – sends the cursor to the end of the command line.
  • CTRL+u – Cut the left portion of command from the cursor position.
  • CTRL+k – Cut the right portion of command from the cursor position.
  • CTRL+r – Search for the commands from command history and execute it.
  • ALT+. – Access the last argument of previous command on the command line.
  • CTRL+w – Delete one word from the command line

Some interesting stuff about running commands

We can run 2 commands one after another using below syntax.
cmd1 ; cmd2

If you want to run second command only if first one is successful, you can use below syntax.
cmd1 && cmd2

If you want to run second command only if first one fails, you can use below syntax.
cmd1 || cmd2

You can run the command in background using below syntax.
cmd &

Complex problems, Simple Solutions