Rpi Basics
π§ Day 2: Linux & Terminal Basics on Raspberry Pi
π― Learning Objectives
By the end of today, learners will:
Navigate the Linux filesystem using the terminal.
Use essential Linux commands for managing files and directories.
Install and remove software using
apt.Understand file permissions and user roles.
Enable and use SSH & VNC to remotely access the Raspberry Pi.
ssh pi1@raspberry1.local
π§ Topics & Content
ποΈ 1. Linux Filesystem Structure
Explain the hierarchy using a tree:
/
βββ bin # Essential binary programs
βββ boot # Boot loader files
βββ dev # Device files
βββ etc # System configuration files
βββ home # User home directories
β βββ pi # Home directory for user 'pi'
βββ lib # System libraries
βββ media # Mounted drives (USB, SD)
βββ opt # Optional application software
βββ tmp # Temporary files
βββ usr # User programs and data
βββ var # Variable data (e.g., logs)
β Tip: Your working directory is usually
/home/pi
Usepwdto check where you are.
π» 2. Basic Linux Commands
Practice the following:
| Command | Description |
pwd | Print current directory |
ls | List contents |
cd foldername | Change directory |
cd .. | Go to parent directory |
mkdir name | Create new folder |
rm file | Delete file |
rm -r folder | Delete folder recursively |
nano file.txt | Open file in editor |
top | Show system processes |
Practice Task:
cd ~
mkdir day2
cd day2
nano hello.txt
π¦ 3. Package Management with APT
APT (Advanced Package Tool) is used for installing and managing software.
Update package list:
sudo apt updateUpgrade installed packages:
dsudo apt upgrade -yInstall a package:
sudo apt install cowsay cowsay "Linux is fun!"Remove a package:
sudo apt remove cowsay
π Explore: Try installing
neofetch,htop, orpython3-pip
π 4. File Permissions and Users
Use ls -l to check permissions:
-rw-r--r-- 1 pi pi 1234 Jun 14 hello.txt
Breakdown:
rw-β owner can read/writer--β group can readr--β others can read
Change permissions:
chmod 755 myscript.sh
Change ownership:
sudo chown pi:pi myfile
User management:
whoami
sudo adduser student
π 5. Remote Access: SSH and VNC
SSH (for terminal access over network)
VNC (for GUI desktop access)
β Enable SSH & VNC:
sudo raspi-config
# Go to "Interface Options" > Enable SSH and VNC
Alternatively:
sudo systemctl enable ssh
sudo systemctl start ssh
π₯οΈ Install VNC Viewer on PC/Mac:
Download: https://www.realvnc.com/en/connect/download/viewer
Enter Raspberry Piβs IP (e.g.,
192.168.1.42) and login
To check IP:
hostname -I
π οΈ Activities
- Create and Navigate Folders
mkdir ~/projects/day2
cd ~/projects/day2
- Edit and View Files
nano notes.txt
cat notes.txt
- Install Software
sudo apt install figlet
figlet "Hello Pi"
- Enable SSH & VNC and connect from another device
π Homework
Try installing any fun terminal program (
cmatrix,sl, etc.)Create a bash script named
myinfo.shthat displays:Current user (
whoami)Date/time (
date)IP address (
hostname -I)
β Summary
Terminal is your gateway to full control in Linux.
You can move, create, and edit files efficiently.
With
apt, you can install nearly anything.SSH and VNC let you work remotely from any device.
LED Blinking with Raspberry Pi
To make an LED blink on a Raspberry Pi, you'll need:
π§° Hardware Requirements
Raspberry Pi (any model with GPIO)
1x LED
1x 330Ξ© resistor
Breadboard and jumper wires
βοΈ Wiring
Connect like this:
| LED Pin | Connects to |
| Anode (+) | GPIO pin (e.g., GPIO 17) via resistor |
| Cathode (β) | GND on Raspberry Pi |
π Example:
GPIO 17 β Resistor β LED anode
LED cathode β GND
π» Python Code to Blink LED
You can use the gpiozero or RPi.GPIO library.
β
Using gpiozero (simpler):
from gpiozero import LED
from time import sleep
led = LED(17) # GPIO pin 17
while True:
led.on()
sleep(1)
led.off()
sleep(1)
β
Using RPi.GPIO:
import RPi.GPIO as GPIO
import time
LED_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
βΆοΈ To Run the Script
Save it as
blink.pyOpen terminal and run:
python3 blink.py
Let me know if you want to:
Control the LED via a web interface
Blink with different patterns
Use a button to control it
LED.html
<!DOCTYPE html>
<html>
<head>
<title>LED Control</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding-top: 50px;
}
button {
padding: 15px 30px;
font-size: 18px;
margin: 10px;
cursor: pointer;
border: none;
border-radius: 8px;
}
.on {
background-color: #4CAF50;
color: white;
}
.off {
background-color: #f44336;
color: white;
}
</style>
</head>
<body >
<h1>LED Control</h1>
<p>Current LED status: <strong>{{ 'ON' if status else 'OFF' }}</strong></p>
<a href="/on"><button class="on">Turn ON</button></a>
<a href="/off"><button class="off">Turn OFF</button></a>
</body>
</html>
flask_led.py
from flask import Flask, render_template
import RPi.GPIO as GPIO
app = Flask(__name__)
# GPIO setup
LED_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, GPIO.LOW)
def is_led_on():
return GPIO.input(LED_PIN) == GPIO.HIGH
@app.route('/')
def index():
return render_template('led.html', status=is_led_on())
@app.route('/on')
def turn_on():
GPIO.output(LED_PIN, GPIO.HIGH)
return render_template('led.html', status=is_led_on())
@app.route('/off')
def turn_off():
GPIO.output(LED_PIN, GPIO.LOW)
return render_template('led.html', status=is_led_on())
@app.route('/cleanup')
def cleanup():
GPIO.cleanup()
return "GPIO Cleaned up!"
if __name__ == "__main__":
try:
app.run(host="0.0.0.0", port=5000, debug=True)
finally:
GPIO.cleanup()

