3.2: Linux (Raspbian) Commands
- Page ID
- 204673
Keyboard Shortcuts
<ctrl><alt><t> - opens the command line terminal
<ctrl>l Clear screen
<ctrl> u wipes out from where you are to the beginning
<ctrl>a jump to beginning of a line
<ctrl> e goes to end of line
<ctrl>C - kills a running command.
Your Rapsberry Pi using Raspbian, which is a type of Linux operating system.
Note: these commands have been adapted from multiple resources on the web, including but not limited to
File Management
- cat<file>: Displays content of a file (concatenate)
cat /home/pi/readme.txt
- cd<path>: change directory (directs to specific directory in tree)
cd /home/pi cd #by itself takes you home
- cp<file or directory><destination>: Copies file or directory to new location, to include subfolders (all content) you need to add -r (recursive)
cp file.txt /home/pi/mydocuments cp /home/pi/mydocuments/file.txt /home/pi/experiment_folder cp -r /home/pi/mydocuments/ /home/pi/experiment_folder
- find <file name>
Needs to be developed - grep <string><location>: (Global Regular Expression Print) Finds a string in a file or script
Needs to be developed
- head <file>: Displays the head (beginning of a file)
head /home/experiments/lab1.txt head -n20 /home/experiments/lab1.txt (displays first 20 lines of lab1.txt
- ls: list files and directories in the current folder (or a specific folder if specified)
ls ls /home/pi ls -1 (one, to make a single column) ls -l (long, to list info) ls -l -a (long and all, to include hidden files
- mkdir <folder>: creates a new subfolder in the current folder, or the specified folder
mkdir <new folder name.> mkdir /home/pi <new folder name
- more<file>: Displays content of file, use enter or space to scroll through pages, q to quit. Often useful for monitoring logfiles
more /file_directory/filename.ext more /var/log/slyslo
- mv<source><destination>: moves a file or directory to a new location
mv /home/pi/work/myfile.txt / /hom/pi/experiments/ mv /home/pi/work/ /home/pi/experiments/
- nano<file>: Linux text editor (CTRL+O, Enter of CRTL +X saves changes)
nano /home/pi/myscript.sh
- pwd: Print current Working Directory (shows what directory you are in
pwd
- rm <file>: Deletes file, to delete a folder use -rf (recursive force)
rm myscipt.sh rm -rf /home/pi/scripts
- tail <file>: displays the end of a file (useful for seeing latest entries on logfiles)
tail /var/log/syslog tail -n20 /var/log/syslog (display twenty lines) tail -f /var/sys/syslof (displays new lines in real time)
- tar
- tar -c: store tar (compressed) files
tar -cvfz arcjove/tar/gz /home/pi/Documents/mydirectory -c creates archive -v verbose -f filename of archive to follow -z compress files with gzip
- tar -x: extract files
tar -xvfz archive.tar.gz
- tar -c: store tar (compressed) files
- tree: shows tree in directories
tree
General Commands
- clear : clears terminal screen
- date : gives current date
- history : Gives a history of commands the last time the pi was run
- poweroff : Shuts the Pi down (Need to find keyboard shortcut)
Network Commands
The Pi comes with two Network Interfaces, ethernet (eth0) and WiFi (wlan0)
Configuration
- ipconfig: Diplays current IP donfiguation (ip a) is shortcut
ifconfig ip a
- ping<ip>: Sends ping package to another IP on network to see if host is up
ping 111.111.1.1
File Transfer-Remote Connection
- wget<url> allows you to download a file from internet
wget https://URL
- ssh<user>@<ip>: Protocol to allow you to remotely connect to computer over web.
ssh root@111.111.1.1
Package Management
- apt-get install <package> installs a package
sudo apt-get install phpmyadmin
- apt-get remove <package> removes previously installed package
- apt-cache search <package name> searches for package name in package list (repository)
sudo apt-get search php
- dpkg -l List installed packages on system. Can be used with grep to find specific package
dpkg -l
dpkg -l | grep myadmin
Raspbian Commands
- raspi-config: allows you to manage configuation from terminal or ssh
sudo raspi-config
- raspi-gpio: Allows you to control gpio ports
Need to develop - raspistill: takes an image with camera plugged to pi camera port
raspistill -o imag.jpg
- raspivid: takes a video with camera, the time is in milliseconds
raspivid -o video.h264 -t 10000
- raspividyuv or raspiyuv: allows video stream
raspividyuv -o video.yuv
System Management
- htop: displays information on running processes (like top, but has more info)
htop
- kill <pid>: kills a process by it's process ID (which you can get with the ps command)
kill 12345 (Kills process ID 12345, but does not step the script and goes onto the next command of the program) kill 12345 -9 (Kills process 12345 and exits the program)
- ps: displays running processes, to display everything
ps aux
to display a specific user
ps -u pi
- reboot : reboots the pi
sudo reboot
- service <service name><action>: Allows you to start/stop services
service apache 2 start
service apache 2 stop - service apache2: (shows actions available for a service)
service apache 2- update-rc.d<service><action>: On Debian, allows you to start/stop service on system boot
sudo update-rc.d ssh enable - update-rc.d -f ssh remove: Disables start of service (-f option "forces")
sudo update-rc.d -f ssh remove
- update-rc.d<service><action>: On Debian, allows you to start/stop service on system boot
NOTE: These commands are only for services, to start other scripts/commands on boot you need to edit the local etc/rc/local file
sudo nano /etc/rc.local
- shutdown -h now : shuts down (halts) the pi
sudo shutdown -h now
- shutdown -h <time> : shuts the Pi at specific time
sudo shutdown -h 08:00
- shutdown -r : shuts down and reboots the pi
sudo shutdown -r - vcgencmd measure_temp: Displays current CPU temperature
vcgencmd measure_temp
System Updates
- apt-get update: Use to synchronize your list of packages with the most, should be run before upgrading packages to ensure you have the most recent versions
sudo apt-get update
- apt-get upgrade: Upgrades installed software packages
sudo apt-get upgrade
- rpi-update: Updates everything (only use if you know what you are doing)