The first thing you need to do is open up a terminal.
Click on ‘LXTerminal’ on the Raspbian desktop.
You should now see a line that looks like:
pi@raspberrypi ~ $
This is the command prompt. Whenever
you see this, you know the system is
ready to receive input. Now type
pwd
,
and press
Enter
. You should see:
/home/pi
If you’ve changed your username, then
you’ll see a different line. The rather
cryptically named
pwd
command stands
for Print Working Directory, and the
system simply outputs the directory you’re
currently in. When you start a terminal,
it will go to your home directory.
Now we know where we are, the next
logical thing to do is move about through
the directories. This is done using the
cd
(change directory) command. Try entering:
cd ..
pwd
You should find that the system returns
/home
. This is because we’ve
cd
ed to
‘
..
’ and two dots always points to the
parent directory. To move back to your
home directory, you can enter
cd pi
.
There is also another way you can do
it. The
~
(pronounced tilda) character
always points to your home directory, so
wherever you are in the filesystem, you
can enter
cd ~
and you’ll move home.
Now type
ls
and hit
Enter
. This will list
all the files in the current directory. One of
the big advantages of commands is that
we can tell them exactly how we want
them to behave. This is done using flags,
which come after the command and
start with a ‘
-
’. For example, if we want
to list all the files in the current directory
(including hidden ones, which start with a
‘
.
’ on Unix-based systems), we use the
flag
-a
. So, in your terminal, type
ls -a
.
This time, you should see more files
appear. Another flag for
ls
is
-l
. This
gives us more information about each file.
Try it out now by typing
ls -l
. You can
even combine flags, such as in
ls -al
.
Interactive programs
Most of the commands we’re dealing with
here are non-interactive. That means you
set them running and then wait for them
to finish. However, not all command line
programs work like this. For example, when
you first booted Raspbian, it started a config
tool that ran in the terminal. There are a few
other programs that work in a similar way.
Traditionally, the most common has been
text editors that allow you to work on files
if you don’t have a graphical connection.
There are a few quite complicated ones that
are great if you spend a lot of time working
from the command line, but they can be
hard to learn. There’s also an easy-to-use
terminal-based text editor called
nano
.
Enter
nano
followed by a filename at the
command prompt to start it. You can then
navigate around the text file and make any
changes you need. Press
Ctrl+X
to save
your work and exit back to the prompt.
11
Raspberry Pi User Guide.indd 11
08/07/2014 14:44