Blog

admin
August 1, 2020
UrTecPro How To's No Comments

The Ultimate Raspberry Pi Commands Cheat Sheet

Sharing is caring
Raspbian OS Terminalcat [name]Show the contents of the file [name]cd ..Change to parent directorycd [path]Move to the directory at [path]cd /Change to root directorycd ~Change to your home directory – usually “/home/”chmod [who][+,-,=][permissions] [name]Change the permissions for a filechmod 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]findSearch for files and their contentsgrep ‘string’ [name]Search inside one or more files for occurrences of ‘string’head [name]Return all occurrences of ‘string’ within file [name]lsList the contents of the current directoryls -aList all files including hidden filesls -lList the contents of the current directory with more file informationls [path]List the contents of the directory found at [path]man [command]Open the manual/help page for [command]man manOpen the manual/help page for the ‘man’ command (helpception)mkdir [name]Create a directory called [name] in the current working directorymv -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]pwdShow the name of the current working directorypython/python3 –versionShows you what version of Python you currently have installedrm -r *Remove all files and directories from the current working directoryrm [name]Remove the specified filerm *Remove all files from the current working directoryrmdir [name]Remove the empty directory [name] from the current working directorysudo [command]Superuser do. Execute [command] with elevated privileges (Allows you to do things you usually wouldn’t have access to)sudo apt-get ​install [package]Install a packagesudo apt-get updateUpdate the list of packagessudo apt-get upgradeUpgrade the installed packages – must be run after sudo apt-get updatesudo ​chown pi:root [name]Change the owner of the file [name] to user ‘pi’ and set the group to ‘root’​sudo raspi-configLaunch the Raspberry Pi configuration menusudo rebootSafely restart your Pisudo shutdown -h nowSafely shutdown your Pi immediatelysudo suPlaces you in the root directory with root user access – be careful with 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 internetRPi.GPIO Libraryimport RPi.GPIO as GPIOImport the RPi.GPIO module into the python sketchGPIO.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 inputGPIO.setup([pin number], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)Set up the pin at [pin number] to be an input with internal pull down resistanceGPIO.setup([pin number], GPIO.IN, pull_up_down=GPIO.PUD_UP)Set up the pin at [pin number] to be an input with internal pull up resistanceGPIO.setup([pin number], GPIO.OUT)Set up the pin at [pin number] to be an outputGPIO.setup([pin number], GPIO.OUT, initial=1)Set up the pin at [pin number] to be an output with the initial value ‘1’GPIO.output([pin number], 1)Set [pin number]’s value to 1. Note that 1, GPIO.HIGH and True are the same thingGPIO.output([pin number], 0)Set [pin number]’s value to 0. Note that 0, GPIO.LOW and False are the same thingi = 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 codeGPIO.cleanup()Reset all GPIO pins (good practice to call before leaving any program)GPIO.VERSIONReturns current RPi.GPIO versionGPIO Zero LibraryLEDsfrom gpiozero import LEDImport the LED section of the gpiozero libraryled = LED(17)Assign the ‘led’ variable to an LED on pin GPIO 17led.on()Turn on the LED stored in the ‘led’ variableled.off()Turn off the LED stored in the ‘led’ variableled.toggle()Toggle the LED stored in the ‘led’ variable (if it’s off, turn it on and vice versa)Motorsfrom gpiozero import MotorImport the Motor section of the gpiozero librarymotor = Motor(17, 18)Assign the variable ‘motor’ to a Motor object containing the forward and backward drive pin numbersmotor.forward()Activate the forward pin of the variable ‘motor’motor.backward()Activate the backward pin of the variable ‘motor’motor.reverse()Reverse the current motor directionmotor.stop()Stop the motorBuzzerfrom gpiozero import BuzzerImport the Buzzer section of the gpiozero librarybz = Buzzer(3)Assign the variable bz to a Buzzer on pin GPIO3bz.on()Turn the buzzer onbz.off()Turn the buzzer offbz.toggle()Toggle the buzzer’s state (if it’s off, turn it on and vice versa)Servofrom gpiozero import ServoImport the Servo section of the gpiozero libraryservo = Servo(17)Assign the ‘servo’ variable to a Servo on GPIO 17servo.min()Move the servo to its minimum valueservo.mid()Move the servo to its middle valueservo.max()Move the servo to its maximum valueservo.value = 0.5Move the servo to a set numerical point (min = -1, max = 1)Raspi Camera ImageraspistillCommand to take a still image with attached camera, modify with arguments below–width, -wSet image width–height, -hSet image height–quality, -qSet JPEG quality <0 to 100> (75 is most common)–raw, -rInserts raw Bayer data from the camera into the JPEG metadata–output, -oOutput filename (required for saving)–latest, -lAdd latest frame to filename–verbose, -vVerbose debugging information during run–timeout, -tSet a time to wait before capturing an image.–encoding, -eEncoding to use for output file – jpg, gif, bmp, or pngRaspi Camera VideoraspividCommand to take a video using attached camera, modify with arguments below–width, -wSet image width (between 64px – 1920px)–height, -hSet image height (between 64px – 1080px)–bitrate, -bSet bitrate in bits per second (i.e 15 Mbits/s = 15000000)–output, -oOutput filename (required for saving)–verbose, -vVerbose debugging information during run–timeout, -tSet a time to wait before capturing video–framerate, -fpsSpecify the frames per second for recording

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.