A Basic Guide to Using Several Handy Linux Command Line / Shell Commands and Tools
Just the Basics
To customise your Raspberry Pi generally requires a little knowledge of the command shell, even if only running the menu-driven Raspbian configuration tool; the operative word being little.
You don’t need to become a Linux guru to make use of a wide range of handy commands and tools to get the most out of the Raspberry Pi, even when using an all-in-one image such as RetroPie.
You can use the command shell to accomplish tasks including:
- Obtaining a real-time view of running programmes and processes, including their memory and CPU usage.
- Monitoring the system hardware, viewing temperature, voltage, and component speed information.
- Running integrity checks on the filesystem.
- Moving, copying, and renaming files.
- Sharing files with other systems on the network, including PC, Mac, and Linux machines, and accessing shared files from those systems.
- Editing or creating text files, such as those controlling configuration for the Pi’s hardware, and individual programmes.
- For RetroPie, adding or tailoring configuration to support additional hardware, including USB adaptors allowing the use of original controllers for systems such as the PlayStation, N64, Megadrive/Genesis, and the wireless Xbox 360 pad.
Topics Covered in this Guide
- Accessing the Command Line (a.k.a Command Shell)
- Safely Shutting Down the Pi: Using Halt and Shutdown
- Monitoring Temperature, Voltage, and Component Speeds: vcgencmd
- Running a Command at Regular Intervals with the Watch command
- The Top Command: Monitoring Running Processes: CPU and Memory Loads, and More
- Installing Programmes via the Raspbian Package Manager (APT)
- Create Multiple Virtual Shell Instances with the Screen Tool
A Note on Case Sensitivity
Unlike Windows systems, Linux is case sensitive; the names of files and of programmes take case into account, and as such:
are not the same.
It is important to check the case of all file names, directory names, and programme names when using the command shell.
Accessing the Command Line / Shell
To access the shell:
If you are using the RetroPie installation, you can reach the shell from the Emulation Station menu by pressing F4, or using the menu and selecting ‘Quit Emulation Station’.
If you are using a GUI, use the shutdown menu (or equivalent), in which an option to exit to the command line / shell should be present. You could also launch a Shell from the GUI and perform the same commands as listed below.
Safely Shutting Down the Pi – Halt and Shutdown
The Raspberry Pi generally runs a Linux operating system, for example it may be directly running Raspbian (a Raspberry Pi specific variant of Debian Linux), providing a graphical user interface not unlike Windows.
If your Pi, like mine, is running RetroPie, that too is using Raspbian behind the scenes.
Regardless, Linux, as with other operating systems such as Windows, makes use of temporary files whilst running, and does not react well to having the power removed without notice. For stability and reliability, the system should be shut down in an orderly fashion before power is removed.
Assuming that the Pi is presenting a full command shell (rather than a window within the GUI), there are several different commands which can be issued to cleanly shut down the system.
Two simple variants are to achieve an immediate, safe, shutdown are:
sudo shutdown -h now
sudo shutdown alone displays a command help screen.
Further details regarding options to shut down and reboot the system from the command line can be found on the computerhope.com site, here.
Command line monitoring of Temperature, Voltage, and Component Speed
Checking the System Temperature:
Note: this returns the value for the BCM2835 System on a Chip (SoC) as a whole.
Checking the Clock Speed of Various Components:
vcgencmd measure_clock + [component to measure]. The component can be any one of
arm, core, h264, isp, v3d, uart, pwm, emmc, pixel, vec, hdmi, dpi, for example:
Checking CPU speed:
vcgencmd measure_clock arm
This will return a value such as:
Note: divide the result by 1,000,000 to obtain the MHz value (e.g. here the value is 600 MHz, rounded down)
Checking the GPU speed:
vcgencmd measure_clock core
This will return a value such as:
Note: the CPU and GPU speed, and system voltage, are by default dynamically controlled by a governor, which adjusts the values to match the Pi’s usage requirements in real-time. As such the above command is likely to show a lower speed than the applied overclock setting, which is a maximum value. Whilst the governor can be disabled, this is not recommended, and will void the Pi’s warranty.
To check the overclock values are actually being applied, run a tool such as mpime to heavily load the Pi. Then check the values returned for the various
vcgencmd measure_clock commands. It is useful to use a tool such as Screen to easily run two (or more) commands in parallel.
Checking the System Voltage:
vcgencmd measure_volts core
This will return a value such as:
Note: as with CPU and GPU speeds, the system voltage is dynamically controlled, and thus will only show the overclocked value when the Pi is under heavy load.
vcgencmd has extensive variations, providing access to a wide range of hardware metrics. Detailed information can be found on the Elinux site here
The Watch Command – Running a Command at Regular Intervals
The Watch command repeatedly executes an arbitrary command every n seconds. To use Watch, simply type:
watch followed by a command to run. The command will be the same as normally entered directly at the shell command line.
By default the command will be executed every 2 seconds; this can be changed by providing the parameter ‘-n’ followed by the number of seconds required.
For example, to display the system temperature at intervals of 5 seconds:
watch -n 5 vcgencmd measure_temp
To exit the Watch command, press:
Control + 'c'
The Top Command – Monitoring Running Processes: CPU and Memory Loads, and More
It is often useful to view real-time information on the processes and programmes running on the Pi. The native multi-user nature of Linux allows us to connect to the Pi from a remote machine and perform monitoring even when the system is busy running emulators, or stability tests.
To launch the in-built process monitoring tool Top:
At the command line simply type
top and press ‘enter’.
The tool shows a list of everything running, including the CPU and memory usage, and which CPU core the programme or process is affiliated with. The overall system state is displayed at the top of the screen, followed by a list of individual entries.
When looking for performance bottlenecks, for example when overclocking for games emulation, Top provides crucial information:
– is the emulator running the CPU at maximum?
If so, overclocking can help.
– Is the emulator using only a single core?
Perhaps an updated multi-core version is available.
– Maybe unneeded processes are running that can be stopped to provide additional performance.
To exit the Top tool, press ‘q’
Installing Programmes via the Raspbian Package Manager APT
Many Raspbian programmes are available from an online repository in the form of packages. A software package can be installed easily using the command line / shell via the Raspbian OS’s APT Package Management Tool.
The APT maintains a repository of available packages, and their dependencies (other packages which a given package requires). Before installing a new package it is good practice to first update the repository list to ensure that you obtain the latest version of whichever package you wish to install, and to avoid dependency issues.
To update the APT repository, at the command shell, type:
sudo apt-get update
To install a specific package, type:
sudo apt-get install [package_name]
As an example, the following shows the installation of the
tree command (used to visualise the directory hierarchy).
pi@retropie /boot $ sudo apt-get install tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 43.4 kB of archives.
After this operation, 108 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main tree armhf 1.6.0-1 [43.4 kB]
Fetched 43.4 kB in 0s (115 kB/s)
Selecting previously unselected package tree.
(Reading database ... 52828 files and directories currently installed.)
Unpacking tree (from .../tree_1.6.0-1_armhf.deb) ...
Processing triggers for man-db ...
Setting up tree (1.6.0-1) ...
A further example of installing a package follows in the section on The Screen Tool.
Using The Screen Tool to create Multiple Virtual Shell Windows
Installing the Screen package:
As per the instructions in the above section Installing Programmes via the Raspbian Package Manager APT, first update the package repository, then type:
sudo apt-get install screen
The Screen Tool: Basic usage guide
The Screen tool provides a method to run multiple virtual command line / command shell instances simultaneously. Different programs can be run in the separate instances; the user can cycle forwards or backwards through the different screens
To launch the Screen tool:
screen at the command line. The tool will display an information page. Press ‘Enter’ to close the page; you will be returned to the command line / shell, where nothing visibly has changed. The Screen program is now, however, running.
Hold the control key and ‘a’ together (also written as
Ctrl + 'a' or
To Create a new virtual shell instance
Ctrl + 'a', then
Ctrl + 'c'
To access the >Next virtual shell instance:
Press Ctrl + ‘a’, then
Ctrl + 'n'
To access text Previous virtual shell instance:
Press Ctrl + ‘a’, then
Ctrl + 'p'
To exit / quit a virtual shell instance:
At the command line for the specific instance, type
To access the in-built Help page:
Press Ctrl + ‘a’, then
Ctrl + '?'
A useful resource for further details on the Screen tool can be found at Rackaid.com
A Labour of Love
Retro Resolution is entirely a labour of love. Please consider offering a donation if the information here has helped illuminate, enlighten, or otherwise assisted you!
- Links: Raspberry Pi and Gaming Emulation via RetroPie
- Navigating the Raspberry Pi’s File System. Raspbian Linux Shell Commands and Tools – Part 2
Overclocking and Stability Testing the Raspberry Pi
- Part 1: Overclocking
- Part 2: Stress testing the CPU with mprime
- Part 3: Stress testing the RAM with Memtester
- Part 4: Stress testing the SD card storage with the Stability Test Script
Terms and Conditions
© Retro Resolution
4 thoughts on “Don’t Fear The Command Line: Raspbian Linux Shell Commands and Tools – Part 1”
Very useful info, thank you. Up at the Top Command section there is a process regarding “connect to the Pi from a remote machine and perform monitoring even when the system is busy running emulators”. I would like to see what my Pi 2 is doing when I play Gran Turismo 2 on Retropie. How can I do use my laptop to show the real-time diagnostics while I’m in-game?
LikeLiked by 1 person
Hi, glad you found the guide useful.
I connect to the Pi from a laptop using a program called PuTTy. It’s free to download:
To connect to the Pi you’ll need the IP address, which you can get by running the ifconfig command.
Please note that on Pi using only wireless, a SSH (secure shell) connection a won’t work (unless a wired Ethernet cable has been plugged in during the current session . i know this is weird – hopefully a Raspbian update will fix it some time).
You’ll need the Pi’s username and password, which by default are ‘pi’ and ‘raspberry’ respectively.
There are many how-to guides for using PuTTy, so I haven’t written my own; one selected at random which looks okay is:
This guide doesn’t mention that the ‘hostname’ can be an IP address – when connecting to the Pi, enter the IP you got by running ifconfig, e.g.
Connection type: SSH
I also connect to the Pi from an Android tablet, using the free version of JuiceSSH.
Hope this helps – remote monitoring of temperatures, CPU load etc. is very useful when running the emulators.
how do i switch from retropie to raspbian without plugging my rpi3 into a tv.. I would like to do this with putty
I am running the Darish Zone Ultimate image on my pi3b .. . Unfortunately this particular image does not include a desktop mode. I have been attempting to get to the command line interface in order to access the desktop or do whatever needs to be done in order to make it available. Unfortunately whenever I hit at for this system reboots and does not go to a command line. Why would this be? I wonder where I could go in the files of the image and make modifications in order to enable this missing functionality. Thank you in advance for your help!