How to get to grips with your Raspberry Pi's command line interface

To see the man page for ls, type man ls. You can navigate through the page using the up and down arrows, or the page up and page down keys to scroll faster. To search for a word or phrase inside the man page, type /, then the phrase. For example, /-l will find all occurrences of -l.

You can use the N key and Shift+N to scroll forwards and backwards through the occurrences of -l. As we introduce more commands, it's good to take a look at the help and the man page to familiarise yourself with what they do.

Of course, you can always Google a command if you find the text-based help a little off-putting, but staying in the terminal will help you become more familiar with the command-line interface.

How will I know?


Remember we said there's good news and bad news? Well, the bad news is that it can be quite tricky to find commands if you don't know what they're called.

One helpful feature is the man keyword search. This is done with the -k flag. To search for all the programs related to 'browser' on your system, run man -k browser. You'll notice that this lists graphical programs as well as command line ones. This is because there's no real difference between the two. You can launch windows from the terminal, and sometimes even control them.

If you've got Iceweasel (a rebranded version of Firefox) installed on your Pi (it's not on there by default), you can open in a new tab in a currently running Iceweasel window with the command iceweasel --new-tab

We're now going to quickly introduce a few useful commands. rm deletes (ReMoves) a file. mkdir makes a new directory. cp copies a file from one place to another. This one takes two arguments, the original file and the new file. cat outputs the contents of one or more text files. This takes as many arguments as you want, each one a text file, and simply spits their contents out onto the terminal. less is a more friendly way of viewing text files. It lets you scroll up and down using the arrow keys. To exit the program back to the command line, press Q.

We'll use all of these commands in examples below, so we won't dwell on them too long. find is a useful command for finding files on your computer. You use it in the format find location flags. For example, to find every file on your computer that's changed in the last day, run find / -mtime 1

There are more details of what this means, and the different flags that can be used are below.

Power up

Star Wars

You can even watch movies in the command line. To stream this classic, just enter telnet and put some popcorn on

So far, you're probably thinking "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 (see boxout) 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.