Diving in to Raspberry Pi shell

Computer users today are so attached to graphical interfaces. Sometimes it seems that people help computers to do the tasks. Can you imagine how many mouse clicks are required to do something simple? This is visible when the task is cyclic like “find, sort, delete.” Sometimes you find yourself just clicking the mouse and not seeing the result. What you would do half a day clicking the mouse can be performed with the single command line. The question is how to be that smart and feel like a fish in the water in front of the command prompt, shell, or bash – call it however you want. It is a system program that accepts typed commands from used and performs tasks. If you look deeper at almost any program with the graphical interface, you will see that it is only a nice skin that hides the same commands that run when the user clicks buttons. No graphical interface can cower all features of shell commands. So if you start dealing with Linux, then start being a friend to the terminal.

Raspberry Pi terminal commands

Historically Unix computers even didn’t have a graphical interface, so all tasks were performed from the terminal screen. This is why the bash program that handles commands is well polished, is flexible, and offers many amazing features.

How to learn bash commands and write scripts for them? The answer, like elsewhere, is the same – keep doing this, and you will learn. Indeed, don’t afraid to experiment. It becomes even simpler with Raspberry Pi. Just attach network cable, run PuTTY, and keep practicing. No problem if something goes wrong – in the worst-case scenario, you could load a new image into the SD card and continue. Internet is full of tutorials and guides; pick one and go.

Bear in mind that the command line is not as warm as GUI. It is more designed for computer programs rather than humans. But in time, you can see a pattern. Simple rules make this obvious. Let’s get warmed up with a few useful commands. Probably you are familiar with the Sudo command. In many cases, it stands in front of most commands, which tells to run the command as a superuser. In Linux systems, you are not advised to run as an administrator. So if you need administrator privileges, add sudo. In many cases, you may find typing sudo before almost every command. For this is a simple command variable -i, which runs shell with superuser privileges:

sudo -i

The most common task in any operating system is working with files and directories. When you are in the terminal program, you need to be aware of where you are currently. After initial login to Raspberry Pi normally, you have located in the /home/me directory. You can check your current location by typing the command.

pwd

it shows current directory you are in – this is called working directory.

raspi_pwd

Once we know where we are, we probably want to know what’s inside this directory. Just type another command.

ls

It lists all the files in it. Let’s say we want to navigate to another directory, for instance, Desktop. For this, we should use the cd command with the directory path. If a directory is inside the working directory, we can type its name after the command.

cd Desktop

if we need to get back, then we type

cd ..

Don’t forget a space after cd! If we want to go to the specific directory, we should type in the full path. For instance, if we want to get to the usr directory, we should type

cd /usr

Since you are logged in as a user named pi, you can get any time to the user directory by typing

cd ~pi

this gets you to /home/pi directory.

Few rules must be kept in mind while working with files in Linux based systems:

  • File names are case-sensitive. The same file name with Upper case and lower case characters represents different files.
  • Avoid using spaces in file names. It gets messy when writing complex commands. Better use underscores, dashes to combine several words in to file name.
  • Everything is a file in a Linux system.

This only a scratch of the surface. We will try more interesting commands next time.

Leave a Reply