What is bash?

linux-penguinBash is the Bourne Again Shell and it's the default shell used in most Linux distributions. This article will describe some of the tricks that I use when running commands in bash.


Open a Terminal

To update the repository lists:

$ sudo apt update

To update the repository list, and if successful upgrade the operating system:

$ sudo apt update && sudo apt dist-upgrade

To update the repository list, and install nmap regardless of whether the first command was successful:

$ sudo apt update; sudo apt install nmap

To repeat the last command:

$ !!

Sometimes I forget to include sudo in a command, so to easily run it again:

$ sudo !!

Show the error code of the previous command (note that 0 indicates no error):

$ echo $?

Create an alias of a command (add them to the ~/.bashrc file to make them load for each bash session):

$ alias install="sudo apt-get install"
$ alias upg="sudo apt update && sudo apt dist-upgrade"
$ alias c=clear

Change directory to previous directory:

$ cd -

Show the IP address:

$ ip address

Show DNS settings

$ resolvectl

 

Shortcuts

Ctrl + a Move the cursor to the beginning of the line
Ctrl + e Move the cursor to the end of the line
Ctrl + l Clears the screen
Ctrl + k Deletes characters to the end of the line
Ctrl + u Deletes a complete line (including a password if you've forgotten what you've typed)
Ctrl + w Deletes the word to the left
Ctrl + r Search your history

 

Thanks for visiting,
Steven