← Advanced Instrumentation

Student reference

Linux command-line guide

PHYS 351 STUDENT GUIDE
Essential Linux Commands for the Preconfigured Raspberry Pi 5

© Ran Yang, Ph.D.

1. Before You Begin

The teaching assistants have already prepared the Raspberry Pi 5 computers, accounts, Python libraries, and lab interfaces for PHYS 351. This guide contains the commands you need for normal lab work.

Do not run system-administration commands on the shared lab Pis. Do not update the operating system, install packages, change users or groups, edit system configuration, or reboot a shared Pi unless a TA asks you to. If a command reports that a program or library is missing, show the TA the error.

Commands in this guide are typed in the Terminal. Press Ctrl+C to stop a running program.

2. Navigate and Organize Your Files

# Show the folder you are currently in
pwd

# List files in the current folder
ls
ls -la

# Make a folder for a lab and enter it
mkdir lab_files
cd lab_files

# Move up one folder or return to the previous folder
cd ..
cd -

# Create an empty file
touch notes.txt

# Copy or rename a file
cp source_file.py copy_of_source_file.py
mv old_name.py new_name.py

# Read a file; press q to leave less
cat notes.txt
less notes.txt

# Edit a file; Ctrl+O saves and Ctrl+X exits nano
nano notes.txt

Use your own lab folder and filenames in place of examples such as lab_files and notes.txt.

3. Find and Remove Files Carefully

# Show the first or last lines of a text file
head notes.txt
tail notes.txt

# Search for text inside a file
grep "GPIO" your_script.py

# Find Python files below the current folder
find . -name "*.py"

# Remove one file only after checking its name
rm filename.txt

# Remove an empty folder
rmdir empty_folder

There is no Recycle Bin in the Terminal. Do not use rm -r or any command containing sudo unless a TA gives you the command.

4. Run Python and GPIO Programs

# Check the Python version
python3 --version

# Run a Python program in the current folder
python3 your_script.py

# Start Python interactively; type exit() to leave it
python3
exit()

GPIO numbering: The course uses BCM numbering. A script should include GPIO.setmode(GPIO.BCM) before setting up pins.

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
sleep(1)
GPIO.output(18, GPIO.LOW)
GPIO.cleanup()

The lab image already contains the libraries used in the course. Do not install a replacement library or mix RPi.GPIO and gpiozero in the same script without checking with a TA.

5. Take a Raspberry Pi Desktop Screenshot

Use these commands only from the Pi’s graphical desktop, not from Raspberry Pi OS Lite or a plain SSH shell. The current desktop normally uses Wayland.

# Check the type of desktop session
printf '%s\n' "${XDG_SESSION_TYPE:-not-set}"

# Wayland: save a full-screen screenshot in your home folder
grim "$HOME/screenshot-$(date +%Y%m%d-%H%M%S).png"

# Wayland: select an area, then save it
grim -g "$(slurp)" "$HOME/selection-$(date +%Y%m%d-%H%M%S).png"

If the screenshot command is missing or fails, do not install packages yourself; ask a TA. For an X11 session, the TA may provide the gnome-screenshot command.

6. Check the Network and Transfer Files

# Show the Pi's current IP address
hostname -I

# Test whether the Pi can reach the internet
ping www.google.com
# Press Ctrl+C to stop ping

# Copy a report from the Pi to your laptop
scp your_username@raspberrypi.local:/home/your_username/report.pdf .

# Copy a file from your laptop to the Pi
scp report.pdf your_username@raspberrypi.local:/home/your_username/

Replace your_username, the hostname, and filenames with the values used at your lab station. Your Pi and laptop must be on the same network. Ask a TA if SSH or file transfer is part of the day’s lab and does not work.

7. Finish a Lab Session

# Show how much free space remains
df -h

# Leave the current shell or SSH connection
exit

Save your programs, data, plots, and screenshots to your approved storage location before leaving. Do not power off or reboot a shared lab Pi; follow the TA’s end-of-lab instructions.

8. Built-in Help

# Show a command's manual page
man ls

# Show a short command summary
ls --help

# Show commands related to a topic
apropos temperature

When in doubt, stop and ask a TA before using sudo or a command that changes or deletes files.

← All course materials