Finding and Learning Linux Commands - dummies

Finding and Learning Linux Commands

By Richard Wentk

Because you can’t guess Linux commands and switches, you have to know how to find them. If you use the command line a lot, you’ll learn the most useful commands by heart without really trying to.

A lot of people write out a cheat sheet to help them learn commands and switches. Unless you have the best memory in the history of the universe, you’ll probably forget some of the commands and switches on your sheet. This is normal, so it’s handy to have a list to remind you.

You can find the most useful commands online. The following figure shows one of the many sites that list popular Linux commands, with some of their switches.


In theory, you can use a Linux command called man to find out more about a command. When you type man [commandname] and Enter, you’ll see lots of details. Helpful? Not really. man is great for experts. It’s not designed for beginners. The help is extremely technical, so it’s very hard to understand. And it doesn’t list switches in order of usefulness. Obscure switches no one uses get equal billing with essential switches that are really useful. So it’s best to ignore man and look for help online.

Playing with cd and ls

To get started with commands, play with two — cd, and ls.

ls is short for — who knows? List something? Lively snowbunnies? Letter soup? It’s a classic magic word command. It looks a bit like list files, but you’d never guess unless someone told you.

cd is short for change directory. You can use it to explore the directories (folders) in your Pi. When you type cd and a directory name, you move to that directory. (Technically, you set the working directory.) You can now list files, copy files, delete files, and generally do useful things without having to type the directory path again.

Directory and folder mean the same thing. When you look at files on the desktop, they’re collected into folders. There’s even a small folder icon to remind you of this. But back in the days of computer prehistory, these folders used to be called directories. They’re two ways to look at the same thing. One way has a pretty picture, and the other has text commands. But both work on the same files. Two views. One thing. K?

If you’ve tried ls, you know what’s in your home pi directory. But what other files live inside your Pi?

Type cd / and press Enter. Now you’re in the Pi’s top directory. It holds all the files in your Pi. Type ls and Enter. You should see the list of directories shown in the following figure.


Files are organized in a big upside-down tree, with the / directory at the top, and lots of other directories inside it. The directories keep branching out and down for a good few levels. You also know that every file and folder has a unique path, so you can find it.

You can use cd to move to any directory by typing its path after the command. Unlike File Manager, it won’t show you all the other directories you could be in. But the idea is sort-of similar-ish, kind of, if you squint and scrunch up your face and don’t think about it too hard.

For example, cd /home/pi takes you back to the pi user directory.

You have to press Enter after every command. This tells your Pi to stop waiting and do what you want. You’ve probably figured this out now, so for now, just assume that you need to press Enter at the end of every command to make it work.

Learning more about cd

Typing full paths wastes time, so cd includes some shortcuts you can use. You can use these shortcuts and the full command with a path to cd to any directory in your Pi. The following table summarizes the shortcuts.

Using cd to Get Around
Command What It’s For
cd ~ Go to your home directory.
cd / Go to the top directory which holds all the others.
cd directory Go into a directory inside the current directory
(only works if that directory exists).
cd .. Go back up to the previous directory.
(You can keep doing this until you get to /.
The space before the dots is important!)
cd /path Go straight to a directory when you know its path.
(The / is important!)

Here’s an even faster shortcut. You can use ls and a path to list the files in a directory without cd-ing to it first. So why use cd? Because if you want to copy, move, or rename files in a directory, it’s best to move there first with cd and save yourself some typing.

Try cd a few times and see what happens. If you’re paying attention, you see the prompt changes when you run it. The prompt shows you the current path. This is great — you don’t have to remember where you are. The prompt always tells you.

To save space, some paths, like the home directory, use the shortcuts shown in the table in this article. If you want to see a full path for the current directory, use a command called pwd — which is short for print working directory. It prints to the screen, and it doesn’t make any kerchunk noises.