Power up
So far you’re probably thinking to yourself, “I could have done all this in the graphical
interface without having to remember obscure commands and flags.”
You’d be right, but that’s because we haven’t introduced
the more powerful features yet. The first of them are
wildcards. These are characters that you can put in that
match different characters. This sounds a bit confusing,
so we’re going to introduce it with some examples.
First, we’ll create a new directory, move into it and create
a few empty files (we use the command
touch
, which
creates an empty file with the name of each argument).
Hint – you can use tab completion to avoid having
to retype long names, such as in the second line.
mkdir wildcards
cd wildcards
touch one two three four
touch one.txt two.txt three.txt four.txt
Then run
ls
to see which files are in the
new directory. You should see eight.
The first wildcard we’ll use is
*
. This matches any string
of zero or more characters. In its most basic usage,
it’ll match every file in the directory. Try running:
ls *
This isn’t particularly useful, but we can put it in
the middle of other characters. What do you think
*.txt
will match? Have a think, then run:
ls *.txt
to see if you are right.
How about
one*
? Again, run
ls one*
to see if you were correct. The wildcards can be
used with any command line programs. They’re
particularly useful for sorting files. To copy all the
.txt files into a new directory, you could run:
mkdir text-files
cp *.txt text-files
We can then check they made it there correctly with:
ls text-files/
The second wildcard we’ll look at is
?
. This matches
any single character. What do you think:
ls ???
will match? Have a guess, then
run it to see if you’re right.
We can also create our own wildcards to
match just the characters we want.
[abc]
will
match just a lower-case A, B and C. What do
you think
ls [ot]*
will match? Now try
ls [!ot]*
What difference did the exclamation mark
make? It should have returned everything that
didn’t start with a lower-case letter O or T.
sudo
When using the Raspberry Pi for normal use,
you can work with files in your home directory
(for example,
/home/pi
). You will also be able
to view most other files on the system, but you
won’t be able to change them. You also won’t
be able to install software. This is because Linux
has a permissions system that prevents ordinary
users from changing system-wide settings. This is
great for preventing you from accidentally breaking
your settings. However, there are times when
you need to do this. You can use
sudo
to run a
command as the super user (sometimes called
root), which can do pretty much anything on the
system. To use it, prefix the command with
sudo
.
For example:
sudo apt-get install synaptic
will install the package
synaptic
and make it
available to all users.
14
Raspberry Pi User Guide.indd 14
08/07/2014 14:44