Using sudo su to enter root mode

42 of the Most Useful Raspberry Pi Commands

Sometimes it’s hard to keep track of all the Raspberry Pi commands you use, so I created a list of some of the most useful and important ones that will make using Linux on the Raspberry Pi a lot easier. But first a quick note about user privileges…

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 can’t be performed with basic privileges, so you’ll need to enter them with super user privileges to perform them. You’ll frequently see the prefix sudo before commands, which means you’re telling the computer to run the command with super user privileges.

An alternative to entering sudo before each command is to access the root command prompt, which runs every command with super user privileges. You can access root mode by entering sudo su at the command prompt. After entering sudo su, you’ll see the root@raspberrypi:/home/pi# command prompt, and all subsequent commands will have super user privileges.

Most of the commands below have a lot of other useful options that I don’t mention. To see a list of all the other available options for a command, enter the command, followed by - -help.

BONUS: Download a PDF version of this list so you can keep it handy and refer back to it whenever you want.

General Commands

  • apt-get update: Synchronizes the list of packages on your system to the list in the repositories. Use it before installing new packages to make sure you are installing the latest version.
  • apt-get upgrade: Upgrades all of the software packages you have installed.
  • clear: Clears previously run commands and text from the terminal screen.
  • date: Prints the current date.
  • find / -name example.txt: Searches the whole system for the file example.txt and outputs a list of all directories that contain the file.
  • nano example.txt: Opens the file example.txt in the Linux text editor Nano.
  • 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 and Directory Commands

  • cat example.txt: Displays the contents of the file example.txt.
  • 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 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).
  • 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 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.
  • rm example.txt: Deletes the file example.txt.
  • rmdir example_directory: Deletes the directory example_directory (only if it is empty).
  • scp user@10.0.0.32:/some/path/file.txt: Copies a file over SSH. Can be used to download a file from a PC to the Raspberry Pi. user@10.0.0.32 is the username and local IP address of the PC, and /some/path/file.txt is the path and file name of the file on the PC.
  • touch example.txt: Creates a new, empty file named example.txt in the current directory.

Networking and 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 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.
  • wget http://www.website.com/example.txt: Downloads the file example.txt 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 print the last command entered into the command prompt. This is a quick way to repeat previous commands or make corrections to commands.
  • 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.

Hopefully this list of commands will make navigating Linux on your Raspberry Pi more efficient and enjoyable. If you have any other commands that you use a lot, leave a comment to let us know! And be sure to subscribe to get an email when we publish new articles!

  • Jim C says:

    Useful list, thanks. But ‘shutdown -r now’ will actually reboot your Pi, not shut it down. It should actually be ‘shutdown -h now’ for a system halt.
    And you might like to add that ‘mv’ is how you rename files, as well as moving them.

  • Jim says:

    A nice wee cheat sheet, thank you very much.
    Also I like how it’s based on the number 42.

  • A note on both the mv and cp command examples:
    `mv ~/examplefile.txt /home/pi/`
    99% of the time for a Pi user, this will do nothing. ~ is a placeholder for the current user’s home directory, if the user is logged into their Pi as the pi user (almost a certainty) – ~ and /home/pi are the same directory. Expanding the example, you have:
    `mv /home/pi/examplefile.txt /home/pi/`

    To move a file in the current working directory it would simply be:
    `mv examplefile.txt /home/pi`

  • Raguvaran says:

    Nice sharing, I have few questions sir,
    1. how to copy the directory from one path to another. And how to create the new user and to change password.
    2. Internet is not connecting in my Raspberry Pi board. so what i should configure to connect LAN?
    Thank you…

    • tux says:

      cp -r sourcedir destdir
      Lookup ‘useradd’ and ‘passwd’ – you’ll want to add the user to some groups too.

      Raspbian will get an ip address if you plug in a working cable. Test with something else.

      • Hank Barta says:

        IMO ‘passwd’ should be the first command on the list. Keeping the default password on a well known account name is a security hole you could drive a truck through.

        As far as the network question, it depends. For Ethernet and most home LANs just connecting a cable should do it. With WiFi he user needs to select the right network from the icon/drop down in the upper right corner and then enter the password. If the WiFi drop down does not list any WiFi access points, the adapter is not working out of the box and more work is required.

  • number says:

    great havent tried it yet

  • Reckoner says:

    Thank you for taking the time to make this list. I’ve been scouring the internet and finally founds yours!

  • joe says:

    excellent post sir….a great help to a recent new adopter. many thanks

  • alex says:

    how to perform native build on raspberry pi?

  • Franco Lanza says:

    they are NOT “raspberry pi” commands. They are Linux and UNIX ( or at least GNU ) commands. Raspberry PI is HARDWARE, not SOFTWARE.

  • Jim says:

    If touch is used on an existing file, it updates the file’s modification time. The sure-fire way to create or empty a file is cat /dev/null > file.

  • ben says:

    Hi, instead of ‘sudo su’, I would prefer ‘sudo -s’ or ‘sudo -i’.

    • Danny Sauer says:

      Seconded. Su is a suid program which starts a shell as a specific user after sanitizing the environment. Sudo is a suid program which runs a commands with another user’s permissions after sanitizing the environment. Chaining both together is what sometime does when they didn’t know how the tools work; it’s like putting your car on a trailer, pulling the trailer to work with a truck, then parking the car. Just take one vehicle, instead of bringing the limitations of both. :)

      As a rule, use “sudo -i” if possible. There are more complete explanations of why all over the Internet; this post is already long enough without adding that rant as well…

  • Dean Murray says:

    Nice Linux primer with some rpi flavour. If you are going to include up arrow for previous command then you just HAVE to include about tab completion. But I guess that will mess with your 42

  • Vladimir says:

    Ping – there is bug in the Jessie (Feb.2016), insufficient rights. Fix: sudo chmod u+s /bin/ping

    • LarryP says:

      IMO that is not a bug, as you do not want a regular user account to have access to that. many denial of service thingies use that vulnerability to mess with web servers.

  • J.C. Hobbs says:

    The @ and a couple of other characters don’t work for my pi 3. Is there a patch to fix this? (American English, I suppose is the problem.)

  • Waleed Alrashed says:

    thanks =D

  • kkb says:

    i have a doubt how to rotate the rows and columns in clockwise and anticlockwise direction(using python programming) in raspberry pi? it is possible in C language, so it is possible in raspbian?

  • Karthikeyan says:

    With in 1 hr 30 mints i learned these 42 cmds in Rasberry pi.. Thanks

  • Great resource. Very helpful for those who are new to Linux and RaPi

  • omkar says:

    Useful commands

  • Nahum Rozental says:

    The article is excellent. Many thanks.

  • Henk Stek says:

    Missing ‘history’, which I frequently use. Or just ‘his’ followed by the Tab-key. Next choose your command in the list that comes on the screen, type ‘!’ followed by the number of the choosen command. There you go

  • Oussama Farhat hakha khodha hhhhh

  • Gene B says:

    Im trying to pair 2 Raspberry Pi together and utilize the CPU for a PS3 gaming console. Can anyone help?

  • tux says:

    Sudo -s is probably preferable to sudo su, as you will keep ‘your’ environment. (For a better explanation look it up)

    Apt-get update – this checks software repoisitories for available upgrades
    Apt-get upgrade – will perform the upgrades found from above.
    This is crucially different to article as apt-get update is updating nothing but a list of available software.

    Ifconfig still works but is deprecated, ip addr has replaced it.

    Generally, if you need help with a command use man cmd, e.g ”man cp”. Press q to get back to prompt, arrows and space to navigate.

  • Mark Gowdy says:

    Ctrl-r : Allows you to “Search your command history.” One of the most useful things that I use all the time.

  • Eric Sunshine says:

    Since Raspian is a Debian-based distro, !! is useful, as in:

    You> shutdown -h now
    Pi> no
    You> sudo !!
    Pi> sudo shutdown -h now

    It’s probably got a name, but is often called “plingpling”.

    Saves a lot of irritation.

  • Neil Ferreri says:

    “dpkg -get-selections” should be “dpkg –get-selections”

  • Rixon says:

    apt-get update does not “update your version of raspbian” – it updates the list of available packages in your chosen repositories.

  • Keith says:

    scp is missing destination directory, no? Or does it default to .?

  • Janarthanan says:

    Hai can you please help
    my raspberry pi3-b was working for wifi. But suddenly stoped working one I was connecting touch screen display. I have removed the display.Even now it is not working. When I run iwconfig both l0 and eth0 says no wireless extension. When I run ipconfig, eth0 shows some ip adresses ,but l0 is local loop back. How to activate Bluetooth and wifi

    Ye

  • DIPEN says:

    HEY I HAVE N-COPUTING WITH RASPBERRY PI OS OK

    IN RASPBERRY OS USER WILL CRASH SO HOW CAN I RESET THAT OS

    WHAT IS THE RESET COMMAND OF RASPBERRY OS

  • gGM says:

    Thank you very much

  • AMaX ☮🕉 says:

    Is it the way of shell ? 🤔

  • Mac says:

    Very Useful!
    Thanks for sharing.

  • Joachim Larsen says:

    Curious why you have the iwconfig commands for scanning, but not for joining a particular ssid

  • vamshikrishna boddupelli says:

    I need to make changes in /home/etc/environment
    but i failed to open that file, is there any command to open it

  • Einestein says:

    As a beginer it’s useful information to me thank you very much…..!

  • Really informative, very great article.. keep sharing!

  • gmail signup says:

    These are really very useful commands loved the way it is explained keep it up.

  • gmail.com says:

    Wow, saved a lot of time.. really useful commands.. loved the way it is explained keep it up, thankyou so much for sharing.

  • rediffmail says:

    well you have saved my time found many commands here very helpfull article thanks for this information.

  • hotmail says:

    Thanks for this post it literally saved my time. These commands are indeed useful

  • Vahn Lewis says:

    It is a shame that this list does not include Raspberry Pi specific commands with prefixes of “raspi-*”, “raspi*” or, “rpi-*. I am aware of a few, but wonder whwere is the complete list? Examples: raspi-config, raspistill, raspivid, raspigpio, raspividyuv, rpi-update. Anyone know where these are comprehensively listed?

  • Jerry says:

    How do I get into command prompt???
    Raspberry PI 2 (old). My pi goes straight into KODI.
    I forgot what to press ?
    I dont have terminal. My Putty wont let me SSH in.
    What is the hotkey to get into the comman prompt screen? HELP?

  • MIChael says:

    Nice Cheat Sheet, thanks for posting!

  • Charlie says:

    Hello,
    I am wondering if you could direct me info on how to list ip resolver configuration like DNS nameserver gotten from DHCP?
    Charlie W

  • Leave a Comment

    Your email address will not be published. Required fields are marked *

    Cheat Sheet of the 42 Most Useful Raspberry Pi Commands

    Cheat Sheet of the 42 Most Useful Raspberry Pi Commands

    Enter your name and email and it will be sent to your inbox:

    Consent to store personal information:

    Email me new tutorials and (very) occasional promotional stuff:

    Check your email to get the PDF!