There are two user “modes” you can work with in Linux.
One is a user mode with basic access
privileges, and the other is a mode with administrator access privileges (AKA super user, or root).
Some tasks cannot be performed with basic privileges and you will need to enter into root mode to
perform them. You will frequently see the prefix sudobefore commands, which means that you are
telling the computer to operate the command with super user privileges. Another way is to access
the root command prompt, which operates all commands with super user privileges. Access root
mode by entering sudo su at the command prompt. After entering sudo su, you will see the
root@raspberrypi:/home/pi# command prompt, and all subsequent commands can be
entered without the sudo prefix and still have super user privileges.
Most of the commands below have a lot of other useful options that I have not explained. To see a
list of all the other available options for a command, enter the command, followed by –help.
42 OF THE MOST USEFUL RASPBERRY PI COMMANDS:
General Commands
● apt-get update: Updates your version of Raspbian.
● apt-get upgrade: Upgrades all of the software packages you have installed.
● clear: Clears the terminal screen of previously run commands and text.
● date: Prints the current date.
● find / -name [Link]: Searches the whole system for the file [Link] and
outputs a list of all directories that contain the file.
● nano [Link]: Opens the file [Link] in “Nano”, the Linux text editor.
● poweroff: To shutdown immediately.
● raspi-config: Opens the configuration settings menu.
● reboot: To reboot immediately.
● shutdown -h now: To shutdown immediately.
● shutdown -h 01:22: To shutdown at 1:22 AM.
● startx: Opens the GUI (Graphical User Interface).
File/Directory Commands
● cat [Link]: Displays the contents of the file [Link].
● cd /abc/xyz: Changes the current directory to the /abc/xyz directory.
● cp XXX: Copies the file or directory XXX and pastes it to a specified location; i.e. cp
[Link] /home/pi/office/ copies [Link] in the current directory
and pastes it into the /home/pi/ directory. If the file is not in the current directory, add the path
of the file’s location (i.e. cp /home/pi/documents/[Link]
/home/pi/office/ copies the file from the documents directory to the office directory).
● ls -l: Lists files in the current directory, along with file size, date modified, and
permissions.
● mkdir example_directory: Creates a new directory named example_directory inside
the current directory.
● mv XXX: Moves the file or directory named XXX to a specified location. For example, mv
[Link] /home/pi/office/ moves [Link] in the current directory to
the /home/pi/office directory. If the file is not in the current directory, add the path of the file’s
location (i.e. cp /home/pi/documents/[Link] /home/pi/office/
moves the file from the documents directory to the office directory). This command can also
be used to rename files (but only within the same directory). For example, mv
[Link] [Link] renames [Link] to [Link], and keeps it in
the same directory.
● rm [Link]: Deletes the file [Link].
● rmdir example_directory: Deletes the directory example_directory (only if it is empty).
● scp user@[Link]:/some/path/[Link]: Copies a file over SSH. Can be used to
download a file from a desktop/laptop to the Raspberry Pi. user@[Link] is the username
and local IP address of the desktop/laptop and /some/path/[Link] is the path and file name of
the file on the desktop/laptop.
● touch: Creates a new, empty file in the current directory.
Networking/Internet Commands
● ifconfig: To check the status of the wireless connection you are using (to see if wlan0
has acquired an IP address).
● iwconfig: To check which network the wireless adapter is using.
● iwlist wlan0 scan: Prints a list of the currently available wireless networks.
● iwlist wlan0 scan | grep ESSID: Use grep along with the name of a field to list only
the fields you need (for example to just list the ESSIDs).
● nmap: Scans your network and lists connected devices, port number, protocol, state (open or
closed) operating system, MAC addresses, and other information.
● ping: Tests connectivity between two devices connected on a network. For example, ping
[Link] will send a packet to the device at IP [Link] and wait for a response. It also
works with website addresses.
● wget [Link] Downloads the file [Link] from
the web and saves it to the current directory.
System Information Commands
● cat /proc/meminfo: Shows details about your memory.
● cat /proc/partitions: Shows the size and number of partitions on your SD card or
hard drive.
● cat /proc/version: Shows you which version of the Raspberry Pi you are using.
● df -h: Shows information about the available disk space.
● df /: Shows how much free disk space is available.
● dpkg –get-selections | grep XXX: Shows all of the installed packages that are
related to XXX.
● dpkg –get-selections: Shows all of your installed packages.
● free: Shows how much free memory is available.
● hostname -I: Shows the IP address of your Raspberry Pi.
● lsusb: Lists USB hardware connected to your Raspberry Pi.
● UP key: Pressing the UP key will enter the last command entered into the command
prompt. This is a quick way to correct commands that were made in error.
● vcgencmd measure_temp: Shows the temperature of the CPU.
● vcgencmd get_mem arm && vcgencmd get_mem gpu: Shows the memory split
between the CPU and GPU.