If you’re using a Raspberry Pi computer for your weekend project (perhaps a media centre or a home server) then there is a good chance these useful command line instructions will save you some time.
The Raspberry Pi: Yes, It’s Linux
You’ve imaged your SD card and booted your Raspberry Pi. You’re probably using the Raspbian operating system and updated and configured it so that it meets your requirements. What you may not have realised is that despite the Windows-style icon-driven desktop, Raspbian is a Linux distribution. Several operating systems are available for Raspberry Pi, the vast majority of which are Linux.
Rather than an attempt to get people using Linux by stealth, the Raspberry Pi relies on these operating systems because of their open source origins and versatility.
(And because it’s rather good.)
Now, you can probably use a Linux operating system with a graphical user interface without using the command line, but this is where most of the real power lies.
Want power over your Raspbian-powered Raspberry Pi? Begin by launching LX Terminal.
Raspberry Pi Command Line Basics
We wouldn’t expect you to start using the command line without knowing how it works. Essentially, it is a method for instructing the computer to perform tasks. It’s really not all that different from pointing and clicking, only you’re expected to use text.
When you first access the command line, you’ll see the pi@raspberrypi $ prompt – whenever this is displayed you’ll be able to enter commands.
With a mouse-driven GUI, you can easily switch directories and read their contents. In the command line, you can check which directory you’re viewing by entering pwd (print working directory). Use ls to list the contents of the directory, and change directory by entering cd. For instance, cd edward will switch to a directory called “edward”, while cd.. will always return focus to the parent directory. New directories are possible with mkdir newdir, where “newdir” is the directory label. You can also create a succession of new directories with mkdir –p /home/edward/newdir1/newdir2, where both newdir1 and newdir2 are created, but this will only work with the –p switch.
These are basics of all command line interfaces, and can be easily picked up. What you really need are useful commands.
Display Hardware Information
On a Windows PC or Mac you can easily find hardware information by looking in System or About This Mac. To find out about your Raspberry Pi’s hardware, enter the following:
This will output information about the device’s processor. For instance, where you see BCM2708, this indicates that the chip was manufactured by Broadcom.
Various other hardware information can be found by running commands under the proc directory.
- cat /proc/meminfo displays details about the Raspberry Pi’s memory
- cat /proc/partitions reveals the size and number of partitions on your SD card or HDD
- cat /proc/version shows you which version of the Pi you are using.
All of these details can be used to assess what your Raspberry Pi might be capable of. Further information can be acquired using the vcgencmd series of commands, which can reveal things like CPU temperature (vcgencmd measure_temp). This can prove vital if you’re concerned about airflow.
Other technical commands include free -o -h to see how much free system memory is available, while vcgencmd get_mem arm && vcgencmd get_mem gpu will reveal the memory split between the CPU and GPU, something that can be adjusted in the Raspbian config screen (see below).
As with the file structure, the ls command can be used to list items attached to your Raspberry Pi, specifically USB hardware. Use lsusb to display a list of attached devices – you’ll find this crucial for setting up a wireless network, mounting a hard disk drive or attaching any other USB hardware that requires some configuration.
As long as the item is listed here, you should be able to set it up.
Three Important Terminal Commands
Perhaps the most important command line instruction is sudo. This single word instructs Linux-based systems such as Raspbian that the following command is to be carried out with “super user” privileges, an advanced level of access similar to (but not the same as) administrator on Windows computers.
For example, sudo apt-get install synaptic will download and install the synaptic package manager (one of several methods of installing software on the Raspberry Pi).
One of the most common commands for Raspbian users is sudo raspi-config. This opens the configuration screen for the operating system, which has been updated considerably since it was first released.
When you’re done in the Raspberry Pi command line, and you’re using the Raspbian (distro), enter startx to return to the graphical, mouse-driven interface. If, on the other hand, you wish to shutdown, use sudo shutdown –h now to immediately begin the system halt and shutdown process.
You can restart with sudo shutdown –r now. A timed shutdown can be set by including a value, such as 5 minutes, or a time, such as 21:55:
sudo shutdown –h 21:55
Command Line Information Is Power
For many people, command line access on any platform is intimidating.
The useful commands listed here are an attempt to give the Raspberry Pi newcomer the bare minimum to get started with the terminal, a small stepping stone to success with whichever Pi project they decide to start.
If you’re new to the Raspberry Pi, don’t forget to check out our unofficial Raspberry Pi guide.
Meanwhile, if you have any commands that you regularly input into your Raspberry Pi terminal, don’t forget to share them in the comments below.
Featured Image Credit: Osde-Info