BASH Basics: Introduction to BASH

This guide is a beginner-friendly introduction to the BASH shell (https://www.gnu.org/software/bash/), the terminal and general Linux concepts, like file organization. Chances are, if you are not already approaching retirement age, the computers you have used always came with a graphical user interface (GUI). When you start your ODROID SBC, you are greeted with a nice Ubuntu MATE desktop not much different from Windows 10 or OS X. In contrast, a shell or command-line interpreter like BASH seems like a relic from 50 years ago, so why should you leave your comfort zone?

There are several answers to this:

  • You are lazy, just like me. It is better to think a few minutes about a problem and have a tedious, repetitive task automated than doing it yourself.
  • Your SBC has either no video output, like the HC1 or the HC2, or you have it somewhere else and are connected only via network. GUIs over the net are eating bandwidth and are a pain to work with; the lag of everything you do because of the added latency drives you crazy after a while. Command line solutions are usually more responsive and easier to work with on remote connections.
  • You want to understand the system better, and have full control over it. This is also best achieved on the command line in the shell. You are at a lower layer than with a GUI. Your little ODROID is less of a black box, you have fine-grained control and can do more things than with the GUI alone.

Figure 1 - The Ubuntu Mate desktop is a modern GUI
Figure 1 – The Ubuntu Mate desktop is a modern GUI

Figure 2 - The BASH command prompt seems like a relic
Figure 2 – The BASH command prompt seems like a relic

Let us start a terminal now with the default BASH shell and see how it can help us with all these. On Ubuntu MATE, just type CTRL-TAB-T to open the terminal, or shell.

Terminal window

By using the shortcut, you opened an 80×24 character terminal (using a default profile, that can be changed, copied and edited) with the command line at the top. The prompt you see is composed of your user name (usually ODROID), the machine name, a colon, the path or working directory, and a $ sign to show that you are a normal user. The root user would get a # instead, as shown in Figure 2. Later on, we are going to customize this to your liking.

Since you start at your home directory, the home directory shows with the ~ as abbreviation. The ls command shows you the contents of your working directory, similar to opening the File Explorer.

What is a shell?

This terminal runs the BASH shell. A shell is a command-line interpreter which runs in a text window, the terminal. The standard for Linux is BASH. BASH can also read and execute commands from a script, called a shell script.

So far, it has not very spectacular. However, if you use ls -l or ll for short, you already get more information than File Explorer is giving you without going to the Preferences menu to change the settings. But wait, there is more. If you want to see a nice tree of what you have in your home directory, try running the tree command. If it is not installed, install it by running: $ sudo apt update && apt install tree Depending on how many files you have, there can be a lot of output. Limit the output to directories only with tree -d, and if you have a lot of levels you are not interested in at the moment, you can limit to i.e., 2 levels by using tree -d -L 2. When you use a command, you can get an abbreviated summary with:

 $ <command></command> --help
or use:
<command></command> $ man
for a full manual page of it.

File system

With ls / command, you get the contents of the root directory. Everything else you can access is bound to one branch of its tree. For a nice overview, use the following command:

 $ tree -d -L 1 /
The directories you see follow a standard, the File System Hierarchy Standard (FHS). The ones of interest for us are mainly:

  • /bin – Essential command binaries that need to be available in single user mode for all users, e.g., cat, ls, cp.
  • /boot – Boot loader files like the initrd ram disk, the kernel and the ARM device tree blobs for the board. These are also found in /media/boot, the place where the FAT32 partition is mounted from which the ODROID SBC boots.
  • /dev – The device files for everything attached to the ODROID. /dev/mmcblk0 is the eMMC, /dev/mmcblk0p1 is the first partition on the eMMC, the FAT32 boot partition for the ARM processor. /dev/mmcblk0p2 is the system partition which is your root partition if you boot from eMMC. In case of using the SD card, it is mmcblk1 instead of mmcblk0.
  • /etc – This is the place for all system-wide configuration files.
  • /home – The home directories for the users. With standard setup, you have /home/ODROID for the ODROID user, the shortcut for each users home directory is ~.
  • /lib – Libraries for programs in /bin and /sbin.
  • /media – Mount point for removable storage like USB sticks. The boot partition for the ARM processor is also mounted here.
  • /mnt – Temporarily mounted file systems.
  • /opt – Optional software. Things like ffmpeg, Google Chrome, Skype, TeamViewer. If you want to see what’s there, tree -d /opt or just ls /opt gives you the overview.
  • /proc – Virtual filesystem providing process and kernel information, populated by the system.
  • /root – Home directory for the root user, the superuser.
  • /run – Information about the system since last boot.
  • /sbin – Essential system binaries like mount, iw, fdisk, mkfs.
  • /srv – Data served by this system. If you have one of the new HC1 or HC2 or generally use your ODROID as a file server, the recommended place to mount your hard drive to would be
  • /srv/samba or /srv/ftp or /srv/nfs.
  • /sys – Information about devices, drivers and some kernel features. For SBCs, a lot of control is done here. To control the fan on a XU4, you would use:

$ echo 0 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic
to shut it off and
 $ echo 255 > /sys/devices/platform/pwm-fan/hwmon/hwmon0/automatic
to switch it on again.

  • /tmp – Temporary files, often not preserved between reboots.
  • /usr – Contains the majority of (multi-)user utilities and applications. Has its own hierarchy with /usr/bin, /usr/lib, /usr/local, /usr/sbin and so on.
  • /var – Variable files such as logs and spool files.

Useful commands

Now that you know the layout of your system, what are the other useful commands in the terminal besides ls and tree? In the next parts, we are going to cover:

  • The most basic commands, usage, application for ODROID SBCs
  • What happens during startup and login with regard to BASH
  • Customizing the BASH prompt
  • Brief introduction to scripting, including variables, tests, loops
  • Useful one-liners for the command line

Be the first to comment

Leave a Reply