Skip to main content
Chemistry LibreTexts

1.3: Pi OS

  • Page ID
    369576
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Your Raspberry Pi typically uses the Debian Linux operating system and this section will introduce you to some common Linux commands that you will find useful. Linux is an open source operating system that is similar to Unix, but through the GNU project  (GNU's Not Unix) has a General Public License (GNU GPL).  Yes, GNU is a recursive acronym and stand for "GNU Not Linux". The most recent versions of Debian Linux are Buster (released in July 2019) Bullseye (released in August 2021) and if you installed your operating system after November 21, 2020 using the instructions outlined in section 1.1 you have installed Bullseye.

    Linux is the "kernel" of your computer's operating system, and interpreted language that you access through the shell (command prompt) and gives you access to control the hardware on your computer.  Figure When a series of Linux commands are bundled into a script it is often called a BASH script, which stands for Borne Again Shell. We will use BASH scripts both within the Raspberry Pi terminal and through system calls from Python.

    clipboard_eed29fc8ecb29f9e59e1767c62ef18012.png
    Figure \(\PageIndex{1}\): Diagram showing computer kernal connecting hardware to application programs, adapted from Wikipedia Kernel article

     

    Linux File System

    Linux uses a tree structure for the file system, and the contents are placed in folders, which are also called directories.  You can navigate this system with the "File Manager" of the Raspberry Pi Desktop (figure \(\PageIndex{2}\) or through commands like ls (list) and cd (change directory) of a shell terminal (figure \(\PageIndex{3}\)).  You can activate the File Manager by clicking on the two folder icon of the keyboard, and here we are showing the contents of user pi (which is highlighted in the tree structure on the left)

    clipboard_e750ccc813d4e30a3c789a7268161a90e.pngFigure \(\PageIndex{2}\): Raspberry Pi desktop File Manager view of the Filesystem Root Directory showing contents of user Pi. Note in this directory there are 10 other directories and two files. (Belford; CC 0.0)

    Figure \(\PageIndex{2}\) shows the Linux root file structure and unless you know what you are doing you should only add/alter files in your user directory.  Here we are showing the default user directory of pi, and in this directory we have created a program for your python programs.  Not in naming files and directories you should have no blank spaces and we used an underscore in the name Python_programs. We also started the name of the directory with a capital letter, which is a personal preference that will be explained later when we get into key-board shortcuts.

    Pi Terminal

    The terminal icon on the toolbar opens the command shell (figure \(\PageIndex{3}\))

    clipboard_ec450e8a16296082eeb89a2ffd2c691da.png
    Figure \(\PageIndex{3}\): Two shell terminals open on a Raspberry Pi desktop. (Belford; CC 0.0)

    Note you can run more than one terminal shell at a time. The title in the terminal indicates the path.

    Keyboard Shortcuts

    The following is a list of Keyboard shortcuts you can use in the shell terminal.

    • <ctrl><alt>t     - Opens the shell terminal
    • <ctrl>c             - Kills current running command
    • <shift><ctrl>C  - Copy 
    • <shift><ctrl>V  - Paste
    • <ctrl> u            - wipe out from curser to beginning of line
    • <ctrul> a          - jump to front of line
    • <ctrl> c            - jump to end of line
    • <ctrl> l             - clear screen
    • <shift><ctrl>+  - increase shell terminal size
    • <shift><ctrl>-   - decrease shell terminal size
    • <tab>               -auto complete

    Note that <ctrl> c kills a program while <ctrl> C copies highlighted text.

    Keyboarding Tips

    <tab> - auto complete is very useful as it lets you see what directories and commands are available, while also avoiding the issue of spelling mistakes.  In the following example ( top shell of figure \(\PageIndex{4}\)) you are in the pi directory of figure \(\PageIndex{2}\) and hit the following commands.

    P <tab>  - nothing happens as there is more than one folder that starts with P
    <tab>     - hitting a second tab prints the the name of the three folders that start with P, and return the P
    y <tab>  - it now auto completes Python_programs as there is only one item that starts with Py

    clipboard_e8752e9466382533abd1b2322d4d4433b.pngFigure \(\PageIndex{4}\): Copy and Paste Caption here. (Copyright; author via source)

    Note in the bottom shell of figure \(\PageIndex{4}\) a small "p" was typed, followed by two tabs, and resulted in 194 possibilities.  This is because most functions start with a lower case letter and is why I am suggesting you start your folders with a capital letter, as you can then quickly navigate to them without having to type as many letters to come up with a unique name for auto complete to work.

    Note, if you try <tab> on a file it needs to be executable for auto complete to work, or you need to be in the nano editor.

    clipboard_e67c1bf45f0661f7d541e83d27ff6d86f.pngUp arrow moves to previous command in the past

    clipboard_ebe62cbe831c4d284fac6bcb9819030bd.png Down arrow moves to previous command in the future

     

    <History> Gives Indexed list of past commands that were saved if you properly exited. 

    !<Index Number> brings the command in history to the command prompt

    Navigation Commands

     

    cd

    -Change Directory

    cd ..    -  back one level

    cd ~    - home directory

    cd /      - root directory 

    clipboard_e83053fcda1e54c49d8cbb50f8e31d33f.pngcd  commands

     

    clear

    -clear the shell

    cp

    -copy directory or file (change path)

    clipboard_ee0bf728645d05aec1fcfb325c757d368.pngcp filename_with_current_path new_path

    cp - r /current directory/  /new directory/  -allows you to move subdirectories

    cp -r /home/pi/mydocuments/ /home/pi/experiment_folder

    ls

    - list directory contents

    ls *.py  - Shows python files

    ls ../   -Shows other files of current directory

    ls -a   Shows hidden files

    ls -l   -shows permissions

    clipboard_e58273e632b173aa59739e3cdc996f640.pngls -l

    ls -R  -Recursively show list

     

    clipboard_e070f94e220968481cfaee299366b5366.pngls -R

     

     

    mkdir [name]

    -make a directory, where [name] is the name of the directory

    pwd

    - Print Working Directory (shows where you are)

    rmdir [name]

    -remove empty directory

    rm -rf [name]

    -forced and recursive removal of a director [name]

    tree

    -Provides directory structure

    clipboard_e72de20e0852d899ab3e6117ee01819cc.pngtree

     

    System Management

    Pi Configuration Tool

    sudo raspi-config opens the keyboard-based navigation tool. 

    • up/down arrow allows navigation across items
    • right/left arrow allows you to select and finish choices
    clipboard_e5715649e5eef4a74ddb3bf0bf840a020.pngPi Configuration Tool (2022)

    Operating system

    cat /etc/os-release

    • need to be in root directory
    • gives info on CPU
    clipboard_e5b92e7b803538f7eee75a1fa66f8f318.pngIdentify operating system

    cat /proc/version    - information on version of Linux

    clipboard_e03b40d753e10931418e664e5c93cd08d.pngInformation on version of Linux

    top

    top

    clipboard_ef3fafe78f2cff7e30ca9623e5a41b4e5.pngIdentify operating system

    line 1: time, how long system has been up, number of users and load average over last minute, 5 minute and 15 minutes.
    line 2: number of tasks and their states (running, sleeping, stopped), and the number of zombies*
    line 3: CPU info
    line 4: info on memory

    The remaining table gives process ID for running processes and information about those processes.

    *Zombies are like orphaned pieces of old programs that have not been completely removed from memory

    Hardware Information

     

    cat /proc/cpuinfo    - information on CPU

    clipboard_e188d2e66cd9d13f200beab1ef713147d.pngCPU information

    memory functions

    cat /proc/meminfo     -information on memory

    clipboard_e3edc50f5a2a4f48519e1d11b6ebdb33f.pngMemory information

    free -h  -available system memory

    clipboard_ebb7d2be5764cda05593031790eaece01.pngAvailable memory

    CPU Tempera

     

    SD card functions

    cat /proc/partitions  - information of SD card

    clipboard_e5592df6616b8155e39fc274ac763f419.pngSD card information

    df -h  - free disk space (-h human readable)

    clipboard_e20971025724ac440bd6b1e17dcd83d32.pngSD card information

     

    vcgencmd get_men arm && vcgenchmd get_mem gpu  - SoC memory split between cpu and gpuation of SD card

    clipboard_e5b032c180db273720f2ffbee37d2c117.pngSystem on Chip memory split between CPU and GPU

    CPU Temperature

    vcgencmd measure temp  - information of SD card

    clipboard_e4aff2a2f81ab422de073836e86b6d681.pngTemperature of CPU

     

    External Ports

    lsusb - devices attached to USB ports

    clipboard_ea9b5b6dbc06e8e28dca7274a59034a0d.pngDevices attached to USB ports

    CPU Temperature

    shutdown

    sudo shutdown -h now   -shuts down now (h for halt)

    reboot

    sudo reboot   -restarts pi from command line.  You will not need to resubmit password

     

    User Management

    User Permissions

    there are three types of users (owner, group and other) and three types of permissions (read, write and execute)

    clipboard_e2a05d3e39203d2de9f446ec5c91caff5.png
    Figure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    chmod

    -allows you to assign permissions to a file or directory

    clipboard_eca68f4ffe22995c285ad65fdeaca9f42.pngVarious chmod actions

    In the above image ls -l showed that everyone had write permissions for the file demo.txt.  He command chmod a=rw demo.txt  gave everone read and write permissions for the demo.txt document. This was then changed with the command chmod u=rwx, g=rw, o=- demo.txt, which gave the user all permissions, the group read and write and others no permissions.

     

     

     

     

     


    1.3: Pi OS is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?