10 Essential Linux Commands for Your Raspberry Pi

By Richard Wentk

There are thousands of Linux and UNIX commands. No one remembers them all, so you don’t have to either. This is good, because you can get by with just a few for the Raspberry Pi.

  • ls: The ls command shows the files in the current directory unless you tell it otherwise with the –R switch, followed by a path.

    Use the –Al switch to show a detailed listing of all files in the directory, including hidden files.

  • cd: You can hop from directory to directory by typing the full path, including the famous Linux backslashes. If you don’t include a backslash, cd tries to move to a subdirectory. Three magic‐word options include cd .., which takes you up a directory level, cd ~, which takes you to your home directory, and cd /, which takes you to the top of the directory tree.

  • cp: When you type the cp command, follow it with two filenames or file paths. The first is the source (where you’re copying from); the second is the destination (where you’re copying to). You can use ‘*‘ as a magic word called a wildcard to select all the files with a matching name or extension as a source.

    If your destination is a path, the command copies all the source files to that one directory.

  • mv: Use the mv command like cp, following it with a source/from and destination/to filename or path. Instead of copying the files, mv renames them if they’re both in the same directory or moves them if the destination is a path.

    Use the –u switch when you want to avoid overwriting a newer file with an older one.

  • mkdir: The mkdir command makes a new directory in the current directory. Use the –m switch to set the directory permissions so that you don’t have to use the chmod command separately later. If you want to create a chain of directories, use the –p switch followed by the full path. You’ll make all the directories you want with a single command, if they don’t already exist.

  • rm: Beware! The Linux command line has no trash can. When you delete something, you lose it forever. So the rm command deletes the file or directory you specify forever. You can delete all the subdirectories inside a directory with the –rf switch, followed by the directory name or path.

    Was it mentioned that this is very dangerous? You can use the –i switch to confirm that you want every file to go.

  • less: You can use less to view a text file, typing various keys to jump around or even search inside the file — for example, press the space bar to move to the next page or b to move to the previous page.

    There isn’t room to list all the options here, but you can find out more online.

  • nano: Linux includes many text editors, but nano is easy to learn and a good choice for quick edits. To edit a file, type the file name or path after the command. When it’s running, nano shows you a list of some of its keyboard commands as you work. To see all the commands you can use, type CTRL+G.

  • find: In Linux, important files are spread over many directories. You can use the find command to find them.

    This one is less simple than it looks. You have to specify a start directory for the search, usually ‘/‘ so you search everything. And you have to specify a filename with the –name switch. And you have to put sudo first so that you run the command as root. Otherwise, you get all kinds of useless rubbish in the output.

  • sudo: Put sudo in front of any command to give yourself god‐like superuser/root powers. You often need to use this command when fixing permissions.

Add the permissions commands to this list — chmod, chown, and chgrp — and you have most of the basic skills you need to make Linux do what you want.

Some online introductions to Linux tell you to use the man (manual) command to find out more about any command. Don’t do this! Man pages — which is what the command summaries are called — are written by experts, for experts. You’ll get more useful help if you search the web for the command name and “examples.”