cyan-checklist

38 Super Useful Raspberry Pi Commands

When I first started using my Raspberry Pi I was constantly Googling commands to learn how to use my Raspberry Pi. Learning Raspberry Pi commands is important for interacting with your Pi especially if you want to use the Pi remotely using SSH.

Because the Raspberry Pi is linux based, most of the commands in Linux will work on the Raspberry Pi. For a Raspberry Pi beginner this might not make any difference because you don’t know any linux commands. That is okay. These 38 super useful Raspberry Pi commands will help you navigate your Pi, edit critical files, move files, network your Raspberry Pi and much more.

For example one of the first question Raspberry Pi beginners will want to know the Raspberry Pi shutdown command. It can be hard on your Pi if you simply unplug it. Instead issue this command “sudo  halt”. This is ideal if you are using a USB and the Pi is actively copying or writing files. Simply pulling the plug can corrupt cheaper SD cards.

This Raspberry Pi commands list will help you get more comfortable with the CLI (command line interface) and build your knowledge of Linux commands.

  1. apt-get update: Updates your version of Raspbian. Most tutorials will suggest you do this when following them to make sure your build has the latest files. Doing this regularly is a good practice to push security fixes, or update critical files on your Raspberry Pi.
  2. apt-get upgrade: Upgrades all of the software packages you have installed. Similar to the above reason this is an ideal command to issue to stay up to date and squeeze the best performance out of your Raspberry Pi.
  3. clear: Clears the terminal screen of previously run commands and text. This command can prove useful when your CLI gets cluttered or you edit a large file and want to see the commands you have issued above. I tend to do this when navigating around folders so I can remember where I came from or what folders I have already looked in.
  4. date: Prints the current date. Pretty straightforward, if your Pi is giving you the wrong date you should reconfigure your Pi settings and correct it because it will help with updates, time, and other important features on your Pi.
  5. find / -name example.txt: Searches the whole system for the file example.txt and outputs a list of all directories that contain the file.
  6. nano example.txt: Opens the file example.txt in “Nano”, the Linux text editor. I only use Nano to edit files. Nano is very good for Raspberry Pi beginners as it is the most similar to a text editor like Word. An alternative is VIM and is commonly used by programmers but definitely has a learning curve.
  7. poweroff: To shutdown immediately. As mentioned above sudo halt is a better option but if you know you have nothing running poweroff is a great way to power down your Raspberry Pi from the command line.
  8. raspi-config: Opens the configuration settings menu. When you very first set up your Raspberry Pi you are taken the to raspi-config menu where you set the time, choose your language, keyboard, RAM, and a bunch of other settings. If you ever want to go back and edit these options issue the “sudo raspi-config” command.
  9. reboot: To reboot immediately. This will automatically reboot your Pi. When you make certain changes to your Pi like overclocking your Pi you will need to reboot for the change to take effect.
  10. shutdown -h 01:22: To shutdown at 1:22 AM. This is a great command if you want to shutdown your Pi at a specific time.
  11. startx: Opens the GUI (Graphical User Interface). One of the first commands you will want to learn is startx as it opens a familiar environment to explore the Pi’s settings, capabilities and files.
  12. cat example.txt: Displays the contents of the file example.txt.
  13. cd /abc/xyz: Changes the current directory to the /abc/xyz directory. This command will be used countless times on your Pi…remember CD literally stands for change directory and a directory is just another name for folder.
  14. cp XXX: Copies the file or directory XXX and pastes it to a specified location; i.e. cp examplefile.txt /home/pi/office/ copies examplefile.txt 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/examplefile.txt /home/pi/office/ copies the file from the documents directory to the office directory).
  15. ls -l: Lists files in the current directory, along with file size, date modified, and permissions. Another important command that will be used often. This command is great for troubleshooting why you cannot view, remove, or edit a file.
  16. mkdir example_directory: Creates a new directory named example_directory inside the current directory. Again mkdir literally stands for MaKeDIRectory.
  17. mv XXX: Moves the file or directory named XXX to a specified location. For example, mv examplefile.txt /home/pi/office/ moves examplefile.txt 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/examplefile.txt /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 examplefile.txt newfile.txt renames examplefile.txt to newfile.txt, and keeps it in the same directory.
  18. rm example.txt: Deletes the file example.txt.
  19. rmdir example_directory: Deletes the directory example_directory (only if it is empty).
  20. scp user@10.0.0.32:/some/path/file.txt: Copies a file over SSH. Can be used to download a file from a desktop/laptop to the Raspberry Pi. user@10.0.0.32 is the username and local IP address of the desktop/laptop and /some/path/file.txt is the path and file name of the file on the desktop/laptop.
  21. ifconfig: To check the status of the wireless connection you are using  (to see if wlan0 has acquired an IP address).
  22. iwconfig: To check which network the wireless adapter is using.
  23. 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).
  24. nmap: Scans your network and lists connected devices, port number, protocol, state (open or closed) operating system, MAC addresses, and other information.
  25. ping: Tests connectivity between two devices connected on a network. For example, ping 10.0.0.32 will send a packet to the device at IP 10.0.0.32 and wait for a response. It also works with website addresses.
  26. wget http://www.website.com/example.txt: Downloads the file example.txt from the web and saves it to the current directory.
  27. cat /proc/meminfo: Shows details about your memory.
  28. cat /proc/partitions: Shows the size and number of partitions on your SD card or hard drive.
  29. cat /proc/version: Shows you which version of the Raspberry Pi you are using.
  30. df -h: Shows information about the available disk space.
  31. df /: Shows how much free disk space is available.
  32. dpkg –get-selections: Shows all of your installed packages.
  33. free: Shows how much free memory is available.
  34. hostname -I: Shows the IP address of your Raspberry Pi.
  35. lsusb: Lists USB hardware connected to your Raspberry Pi.
  36. 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.
  37. vcgencmd measure_temp: Shows the temperature of the CPU.
  38. vcgencmd get_mem arm && vcgencmd get_mem gpu: Shows the memory split between the CPU and GPU.