Section outline

  • Using Linux Commands and Terminal on Raspberry Pi

    The Raspberry Pi runs on a Linux-based operating system, typically Raspberry Pi OS (formerly Raspbian). Understanding basic Linux commands is crucial for navigating, configuring, and managing your Pi effectively. This section introduces essential command-line skills that will help you control the Pi without relying on the graphical interface.

    • Why Use the Terminal?

      • Lightweight and fast compared to GUI
      • Remote access through SSH
      • Greater control over file system, packages, and hardware
      • Necessary for scripting and automation
    • Essential Linux Commands:

      • pwd – Shows the current directory path
      • ls – Lists files and folders in the current directory
      • cd – Changes the current directory (e.g., cd Desktop)
      • mkdir – Creates a new folder
      • touch – Creates a new file (e.g., touch test.py)
      • rm – Deletes a file, use rm -r for folders
      • sudo – Runs a command with administrator rights (e.g., sudo reboot)

      System Management:

      • top – View running processes
      • df -h – Check disk space
      • free -h – Check RAM usage
      • uptime – See how long the system has been running

      Package Installation:

      • Update the system: sudo apt update and sudo apt upgrade
      • Install software: sudo apt install package-name
      • Example: sudo apt install python3-pip to install Python’s package manager

      File Permissions and Execution:

      • chmod +x script.py – Makes the file executable
      • ./script.py – Runs the executable script
      • sudo nano filename – Opens a file for editing using the nano text editor

      Networking Commands:

      • ifconfig – Displays IP address and network interfaces
      • ping google.com – Tests network connectivity
      • hostname -I – Displays the current IP address of the Pi

      Practical Activity: Open the terminal and try the following:

      cd Desktop
      mkdir test_folder
      cd test_folder
      touch hello.py
      nano hello.py

      Then, write a simple Python script in nano and run it using python3 hello.py.

      Important Tip: Always double-check commands, especially those with sudo or rm, to avoid accidental deletion or system issues.

      With a solid grasp of Linux commands, you can efficiently manage your Raspberry Pi, automate tasks, and access powerful features like remote control via SSH. This foundational skill will be essential as you begin building advanced Raspberry Pi robotics and IoT projects.