2

Getting Started

The Raspberry Pi uses a distribution of Linux called Raspberry Pi OS as its operating system. This chapter introduces Linux and shows you how to use the desktop and command line.

Linux

Linux is an open source operating system. This software has been written as a community project for those looking for an alternative to the duopoly of Microsoft Windows and Apple OS X. It is a fully featured operating system based on the same solid UNIX concepts that arose in the early days of computing. It has a loyal and helpful following and has matured into an operating system that is powerful and easy to use.

Although the operating system is called Linux, various Linux distributions (or distros) have been produced. These involve the same basic operating system, but are packaged with different bundles of applications or different windowing systems. Although many distros are available, the one recommended by the Raspberry Pi Foundation is called Raspberry Pi OS.

If you are only used to some flavor of Microsoft Windows, expect to experience some frustration as you get used to a new operating system. Things work a little differently in Linux. Almost anything you may want to change about Linux can be changed. The system is open and completely under your control. However, as they say in Spiderman, with great power comes great responsibility. This means that if you are not careful, you could end up breaking your operating system.

The Desktop

At the end of Chapter 1, we had just booted up our Raspberry Pi, logged in, and started up the windowing system. Figure 2-1 serves to remind you of what the Raspberry Pi desktop looks like.

Images

Figure 2-1 Raspberry Pi desktop.

If you are a user of Windows or Mac computers, you will be familiar with the concept of a desktop as a folder within the file system that acts as a sort of background to everything you do on the computer.

Clicking the left-most icon on the bar at the top of the screen will show us some of the applications and tools installed on the Raspberry Pi (rather like the Start menu in Microsoft Windows). We are going to start with the File Manager, which can be found under the Accessories.

The File Manager is just like the File Explorer in Windows or the Finder on a Mac. It allows you to explore the file system, copy and move files, as well as launch files that are executable (applications).

When it starts, the File Manager shows you the contents of your home directory. You may remember that when you logged in, you gave your login name as pi. The root to your home directory will be /home/pi. Note that like Mac’s OS X, Linux uses slash (/) characters to separate the parts of a directory name. Therefore, / is called the root directory and /home/ is a directory that contains other directories, one for each user. Our Raspberry Pi is just going to have one user (called pi), so this directory will only ever contain a directory called pi. The current directory is shown in the address bar at the top, and you can type directly into it to change the directory being viewed, or you can use the navigation bar at the side. The contents of the directory /home/pi include the Desktop and various other directories.

Double-clicking Desktop will open the Desktop directory, but this is not of much interest because it just contains the shortcuts on the left side of the desktop. If you open the bookshelf folder, you will see that it contains the single file containing a beginners guide to the Raspberry Pi, as shown in Figure 2-2.

Images

Figure 2-2 The contents of bookshelf, as shown in File Manager.

You shouldn’t often need to use any of the file system outside of your home directory. You should keep all documents, music files, and so on, housed within directories on your home folder or on an external USB flash drive.

The Command Line

If you are a Windows or Mac user, you may have never used the command line. If you are a Linux user, on the other hand, you almost certainly will have done so. In fact, if you are a Linux user, then about now you will have realized that you probably don’t need this chapter because it’s all a bit basic for you.

Although it is possible to use a Linux system completely via the graphical interface, in general you will need to type commands into the command line. You do this to install new applications and to configure the Raspberry Pi.

To open a Terminal window, click on the Terminal icon at the top of the screen (looks like a monitor with a blank screen). This is a few icons to the right of the Raspberry P Menu (see Figure 2-3).

Images

Figure 2-3 The Terminal command line.

Navigating with the Terminal

You will find yourself using three commands a lot when you are using the command line. The first command is pwd, which is short for print working directory and shows you which directory you are currently in. Therefore, after the $ sign in the terminal window, type pwd and press RETURN, as shown in Figure 2-4.

Images

Figure 2-4 The pwd command.

As you can see, we are currently in /home/pi. Rather than provide a screen shot for everything we are going to type into the terminal, I will use the convention that anything I want you to type will be prefixed with a $ sign, like this:

$ pwd

Anything you should see as a response will not have $ in front of it. Therefore, the whole process of running the pwd command would look something like this:

$ pwd

/home/pi

The next common command we are going to discuss is ls, which is short for list and shows us a list of the files and directories within the working directory. Try the following:

Images

This tells us that the /home/pi folder contains the same set of folders that we saw using the File Manager in Figure 2-2.

The final command we are going to cover for navigating around is cd (which stands for change directory). This command changes the current working directory. It can change the directory relative either to the old working directory or to a completely different directory if you specify the whole directory, starting with /. So, for example, the following command will change the current working directory to /home/pi/Desktop:

Images

You could do the same thing by typing this:

$ cd /home/pi/Desktop

Note that when entering a directory or filename, you do not have to type all of it. Instead, at any time after you have typed some of the name, you can press the TAB key. If the filename is unique at that point, it will be automatically completed for you.

sudo

Another command that you will probably use a lot is sudo (for substitute-user do). This runs whatever command you type after it as if you were a super-user. You might be wondering why, as the sole user of this computer, you are not automatically a super-user. The answer is that, by default, your regular user account (username: pi, password: raspberry) does not have privileges that, say, allow you to go to some vital part of the operating system and start deleting files. Instead, to cause such mayhem, you have to prefix those commands with sudo. This just adds a bit of protection against accidents.

For the commands we have discussed so far, you will not need to prefix them with sudo. However, just for interest, try typing the following:

$ sudo ls

This will work the same way ls on its own works; you are still in the same working directory.

Applications

Take some time to look through the applications that are installed along with Raspberry Pi OS by clicking on the Raspberry icon in the top left of the screen and looking inside the various sub-menus. For example, Figure 2-5 shows the applications in the Office category. You can see here that you have word processor, spreadsheet, and presentation software akin to Microsoft Word, Excel, and PowerPoint.

Images

Figure 2-5 Office applications.

Note that your menu may not have the same contents as Figure 2-5 as these often change between versions of Raspberry Pi OS.

Other programs of note are:

Images   Mu within the Programming sub-menu

Images   The Chromium web browser within Internet

Images   A selection of games in Games

Images   Raspberry Pi Configuration within Preferences

Internet Resources

Aside from the business of programming the Raspberry Pi, you now have a functioning computer that you are probably keen to explore. To help you with this, many useful Internet sites are available where you can obtain advice and recommendations for getting the most out of your Raspberry Pi.

Table 2-1 lists some of the more useful sites relating to the Raspberry Pi. Your search engine will happily show you many more.

Images

Table 2-1 Internet Resources for the Raspberry Pi

Summary

Now that we have everything set up and ready to go on our Raspberry Pi, it is time to start programming in Python.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.247