BASH - Tutorial Part 1 - First Steps

In a previous blog entry I explained how to get a Linux system running on Windows (Windows 10).

This is obviously mandatory, because otherwise it is difficult to get a Linux environment quickly up and running in which you can gain first experiences with the BASH.

The technology I used for this is called WSL (Windows Subsystem for Linux).

Following the link to the bloggpost:

Setting up WSL2 (Windows Subsytem for Linux) on Windows 10
Due to my continuing education activities (study Master Cloud Computing Engineering) I have again to deal with Linux/Unix. Especially I want to refresh my ” Bash skills ”. However, in order to be able to start with that, it is necessary to create a training environment. This can be achieved in ma…

Having now access to a Linux system I would like to show you in a first step how to check if you already work with the "BASH" and which version you are using.

To do this, enter the following command in the CLI of the respective Linux system:

echo $BASH
# If you get a "/bin/bash" back, then a BASH is installed.
echo "${BASH_VERSION}"
# This command displays the current BASH version.

Commands & Arguments:

Each input / command in BASH consists of two parts

  • Command
  • Argument
cd "/mnt/c/Users/Thomas/Desktop"

# "cd" stands here for "Change Directory"
# "/mnt/c/Users/Thomas/Desktop" is the target path to switch into.

An argument starting with a dash is called an option

ls -l
# list all files in long format
ls -a
# list all files (including hidden ones)
ls -la
# list all files in long format (including hidden ones)

So far we learned only few commands including their corresponding arguments. Often you do not need many to reach your aim.

For certain tasks, however, it is essential to get more out of the BASH. There is documentation for almost every command. This can be displayed with "man" (manual).

Unfortunately it is sometimes necessary to install this function first.

MAN:

sudo apt update
# updates the available packages (based on package sources listed in the "/etc/apt/sources.list"
sudo apt install man-db
# installs the man - libraries

Below you will find an example of how to display the documentation for the "ls" command:

man ls

Result:

A few more tips on how to deal with the "man":

  • use "space" to move down
  • use "b" to move back
  • use "/" + "Keyword" + "Enter" to search (if you enter only "/" + "Enter" again, you will get the 2nd search result (and so on)).
  • use "q" to exit man

Further helpful tips & information:

History:

It is possible to browse or search the last entered commands with the arrow keys ( ↑ / ↓ ). This simplifies the operation in practice enormously.

The last 500 commands are saved by default. This value can be set in the file ~/.bashrc. With the entry "HISTSIZE=2000" the history is extended to 2000 commands.

By typing

history

you can also output a list of the entered commands.

Autocomplete

Bash offers the possibility to automatically complete commands and file names after the first characters have been entered. This can be achieved by pressing "TAB"