Page 28 - Programming the Raspberry Pi Getting Started with Python
P. 28
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:
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:
This tells us that the only thing in /home/pi is the directory Desktop.
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:
You could do the same thing by typing this:
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 super-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:
This will work the same way ls on its own works; you are still in the same working directory. The
only difference is that you will be asked for your password the first time you use sudo.
Applications
The Raspbian Wheezy distribution for Raspberry Pi is fairly sparse. However, loads of applications
can be installed. Installing new applications requires the command line again. The command apt-get
is used to both install and uninstall applications. Because installing an application often requires
super-user privileges, you should prefix apt-get commands with sudo.
The command apt-get uses a database of available packages that is updated over the Internet, so
the first apt-get command you should use is sudo apt-get update
which updates the database of packages. You will need to be connected to the Internet for it to work.
To install a particular package, all you need to know is the package manager name for it. For
example, to install the Abiword word processor application, all you need to type is the following:
It will take a while for everything that is needed to be downloaded and installed, but at the end of
the process you will find that you have a new folder in your start menu called Office that contains the