Operating Linux from the console

Let's take one step back now, and talk about terminals and consoles for a minute.

If you are not familiar with Linux, maybe you have never used the computer from the command line, but instead have always used the provided Graphical User Interface (GUI). GUIs are great and provide beautiful graphics, animations, and a superior usability experience overall. However, they also demand a lot of resources. And we're not only talking about memory or CPU performance, but peripherals such as keyboards, monitors, and mice. As you noticed, our board has none of these. Of course, you can connect those via the available USB and HDMI ports, but since our target is to build a standalone system, in this book, we will focus on the remote and console operations of our target.

Now, while performing the steps in the previous section, when we logged into the target, we actually started a terminal session. Here, we can control the board with the command line. Using the command line will take some time to get used to; but once you are comfortable with it, it's very fast and efficient to use. Commands can also be chained to be executed sequentially; this is called scripting. You will find a lot of scripts on the Internet that perform a certain task in a specified order. Did you notice that in the Preparing the host machine section for Linux, we set udev permissions with the mkudevrule.sh file? This was also a command-line script. While it's not necessary to become a command-line guru to write and execute programs on our board, we need to go over a few basic things about console operation.

Tip Linux, unlike Windows, does not have a central registry that keeps the information of the system. Everything in Linux is built on top of files, even the hardware under the /dev/ folder. Or more accurately, almost everything is accessible in Linux through the filesystem. Some of the files might not be the actual files that are permanently saved onto a disk, but you can still access (read) them in pretty much the same way. It's important to become at least somewhat familiar with operating on files in the console.

Basic filesystem operations When you log into the system, you are placed in the home folder of the user you used to log in as, in our case, root. Tip In Linux, root is a user that corresponds to an administrator. He can perform all the tasks on the system and has the rights to add other users, perhaps with fewer privileges. For now, we will keep using root even though it is not a good practice in general. You might want to read up on "Linux and user rights" from the Internet. You can always see the current folder with the command pwd (think of it as an acronym for the present working directory): [email protected]:~# pwd /home/root [email protected]:~# You can move between folders with the command cd (change directory).The cd command takes one input parameter that specifies the directory you want to change to. For example, to go one folder up in the hierarchy, you type cd .. .You might have noticed that the current folder structure starts with / . This is the root point of the whole filesystem on our Linux OS. You can go and take a look at it: [email protected]:~# cd / [email protected]:/# ls bin dev home lost+found mnt run sys usr boot etc lib media proc sbin tmp var To list the contents of the current folder, we use the command ls . Here, you can see that there are quite a few folders in the filesystem. For example, /home/folder contains the home folders of all the users of this system. Take another example where, in the folders /bin and /usr/bin , you can find programs and commands that can be executed on this system (programs like ls and pwd are also in the /bin folder). Remember how we said that everything is a file? Well, so are the basic commands! Tip Did you notice that when we navigated away from the root user's home folder to the current folder, the last character changed to show the current folder? This is because ~ is a shorthand to indicate the user's home folder. You can always go back to the user's home folder by just typing cd and pressing Enter.