Element 14 Raspberry Pi User Manual page 14

Table of Contents

Advertisement

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
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
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.
sudo
When using the Raspberry Pi for normal use,
you can work with files in your home directory
(for example,
/home/pi
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
14
Raspberry Pi User Guide.indd 14
touch
, which
*
. This matches any string
). You will also be able
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
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.
match just a lower-case A, B and C. What do
you think
will match? Now try
ls [ot]*
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.
your settings. However, there are times when
you need to do this. You can use
command as the super user (sometimes called
root), which can do pretty much anything on the
system. To use it, prefix the command with
For example:
sudo apt-get install synaptic
will install the package
synaptic
available to all users.
. This matches
?
will
[abc]
sudo
to run a
.
sudo
and make it
08/07/2014 14:44

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Element 14 Raspberry Pi

Table of Contents