Raspberry Pi Commands
Raspberry Pi Commands
Raspbian OS Terminal
Command Result
cat [name] Show the contents of the file [name]
cd .. Change to parent directory
cd [path] Move to the directory at [path]
cd / Change to root directory
cd ~ Change to your home directory - usually "/home/<username>"
chmod [who][+,-,=][permissions] [name] Change the permissions for a file
chmod 777 [name] Allow all users to read, write and execute the file [name]
chmod u+x [name] Allow the user to execute [name]
cp -r [from] [to] Copy all files and subdirectories from source [from] to destination [to]
cp [from] [to] Copy a file from source [from] to destination [to]
find Search for files and their contents
grep ‘string’ [name] Search inside one or more files for occurrences of ‘string’
head [name] Return all occurrences of 'string' within file [name]
ls List the contents of the current directory
ls -a List all files including hidden files
ls -l List the contents of the current directory with more file information
ls [path] List the contents of the directory found at [path]
man [command] Open the manual/help page for [command]
man man Open the manual/help page for the ‘man’ command (helpception)
mkdir [name] Create a directory called [name] in the current working directory
mv -r [from] [to] Move all files and directories from source [from] to destination [to]
mv [from] [to] Move a file from source [from] to destination [to]
pwd Show the name of the current working directory
python/python3 --version Shows you what version of Python you currently have installed
rm -r * Remove all files and directories from the current working directory
rm [name] Remove the specified file
rm * Remove all files from the current working directory
rmdir [name] Remove the empty directory [name] from the current working directory
Superuser do. Execute [command] with elevated privileges (Allows you to
sudo [command] do things you usually wouldn't have access to)
sudo apt-get install [package] Install a package
sudo apt-get update Update the list of packages
sudo apt-get upgrade Upgrade the installed packages - must be run after sudo apt-get update
sudo chown pi:root [name] Change the owner of the file [name] to user 'pi' and set the group to 'root'
sudo raspi-config Launch the Raspberry Pi configuration menu
sudo reboot Safely restart your Pi
sudo shutdown -h now Safely shutdown your Pi immediately
Places you in the root directory with root user access - be careful with
sudo su this!
tail [name] Show the end of file [name]
tar -cvzf [name] [path] Create compressed file [name] from the contents of [path]
tar -xvzf [name] Extract the contents of the compressed file [name]
wget [uri] Download the file found at [uri] on the internet
RPi.GPIO Library
Command Result
import RPi.GPIO as GPIO Import the RPi.GPIO module into the python sketch
GPIO.setmode(GPIO.BCM) Use Broadcom pin numbers (GPIO 14, GPIO 15 etc)
GPIO.setmode(GPIO.BOARD) Use board pin numbers (4,5, 8 etc)
GPIO.getmode() Returns current pin numbering mode (BCM, BOARD, or None)
GPIO.setup([pin number], GPIO.IN) Set up the pin at [pin number] to be an input
GPIO.setup([pin number], GPIO.IN, Set up the pin at [pin number] to be an input with internal pull down
pull_up_down=GPIO.PUD_DOWN) resistance
GPIO.setup([pin number], GPIO.IN, Set up the pin at [pin number] to be an input with internal pull up
pull_up_down=GPIO.PUD_UP) resistance
GPIO.setup([pin number], GPIO.OUT) Set up the pin at [pin number] to be an output
GPIO.setup([pin number], GPIO.OUT,
initial=1) Set up the pin at [pin number] to be an output with the initial value '1'
Set [pin number]'s value to 1. Note that 1, GPIO.HIGH and True are the
GPIO.output([pin number], 1) same thing
Set [pin number]'s value to 0. Note that 0, GPIO.LOW and False are the
GPIO.output([pin number], 0) same thing
Copyright © 2020 MakeUseOf. For more cheat sheets, head over to www.makeuseof.com
i = GPIO.input([pin number]) Set the variable i to the value of [pin number]
if GPIO.input([pin number]): Use the value of [pin number] as a boolean in code
GPIO.cleanup() Reset all GPIO pins (good practice to call before leaving any program)
GPIO.VERSION Returns current RPi.GPIO version
Copyright © 2020 MakeUseOf. For more cheat sheets, head over to www.makeuseof.com