Skip to main content
Chemistry LibreTexts

3.2: Linux (Raspbian) Commands

  • Page ID
  • \( \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}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    This page is being built

    commands to be figured out



    Need to dive into redirect 

    file name > new file name





    Tab autocomplete -- when you hit tab it autocompletes if there is only on file with the same stem.  If you hit it twice, it shows all files with the same stem

    Useful tasks

    • to identify opererating system
     cat /etc/os-release



    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.

    <shift><ctrl>v -paste

    <shift><ctrl>c - copy

    <ctrl>a - jumps you to the front of a line



    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 & Directory Commands

    • cat<file>:  Displays content of a file (concatenate)
      cat /home/pi/readme.txt


    • cd<path>: change directory (directs to specific directory in tree)

    note, there must be a space after cd

    • cd /home/pi
      cd   #by itself takes you home
      cd ~  navigate to home directory
      cd /  navigate to root directory
      cd .. go up one level
      cd - go back one level
    • chmod 
      • three things need to be set
        • who you are setting permissions to

    u-owner of the file
    g - the file group
    o - everyone who is not owner
    a- everyone

    • how you are setting the permissions

    + turns on a permission
    - turns off a permission
    = ignores current permissions and sets  new ones

    • what you are setting them to

    r  read
    w write
    x execute
    X special execute for folders

    change permissions in a file

    chmod 755 filename.txt  (gives all permissions)


    • 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
    • cut cuts a portion of a file usning commas and delimeters.
      • -d flag for delimiters


    • df -h  

    displays disk space and partitions

    • diff
    • find difference between two files
    diff file1.txt file2.txt



    • find <file name>
      program that allows you to find where particular types of data exists across directory structures.
    find / -name passwd
    find / -iname filename.ext  (not case sensitive)


    • Needs to be developed
    • grep <string><location>:  (Global Regular Expression Print) Finds a string in a file or script 
      grep " " filename.txt


    • 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
    • less

    Allows scrolling with up/down arrows

    less /home/experiments/lab1.txt


    • ls:  list files and directories in the current folder (or a specific folder if specified)
      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
      ls ../   (reaches up one level)


    • 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/
    • ps aux 

    displays all running processes

    • ps -u pi

    where pi is user name

    • pwd:  Print current Working Directory (shows what directory you are in
    • reboot
    sudo reboot


    • rm <file>:  Deletes file, to delete a folder use -rf (recursive force)
      rm -rf /home/pi/scripts
    • sed

    can be used for find and replace with s flag

    sed 's/bob/robert' filename.txt  will replace bob with robert

    • shutdown
    sudo shutdown -h now
    sudo shutdown -h 12:05
    • sort

    -k# flag sorts by column number

    sort filename.txt



    • 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


    • tree:  shows tree in directories
    • uniq

    filters out duplicate lines in a test file


    wc:  word count

    wc -l line count



    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)
    • echo

     echo -n   no new line

    echo shows string/text that are used as arguments

    >> appends to file

    echo $!  - gives the exit status of the last command

    =0 means it ran fine
    =1 means it hung up (terminated abruptly)


    • man

    manual - gives options to a command, the following gives options for ls.  Q gets you back to prompt

    man ls
    • TOUCH
      used to create any type of file with zero size
    touch demo.txt


    • cat

    allows you to view a file.  The following command allows you to see what your operating system is

    cat does not support keyboard scrolling

     cat /etc/os-release


    Network Commands

    The Pi comes with two Network Interfaces, ethernet (eth0) and WiFi (wlan0)


    • ipconfig:  Diplays current IP donfiguation  (ip a) is shortcut
      ip a


    • netstat

    shows every port that is open

    • ping<ip>:  Sends ping package to another IP on network to see if host is up

    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@

    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

    • install

    to install packages (need to fix)

    sudo apt-get install vim  (to install the vim editor)

    to remove a package

    sudo apt-get remove vim  (to remove the vim editor)


    • dmesg

    Shows all processes and error when system boots




    • htop: displays information on running processes (like top, but has more info)


    • 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

    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
    • top
    • - shows processes being run


    • vcgencmd measure_temp:  Displays current CPU temperature
      vcgencmd measure_temp

    User Management

    to add user

    sudo adduser name-in-lower-case
    sudo adduser bob

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

    to change password

    -note you will see no characters and it first asks for current password, and then for the new one twice

    - if you have admin privledges you can 

    sudo passwd name (lets someone with sudo privledges make a password for someone else)
    sudo passwd name -d  (deletes password)


    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)



    This page titled 3.2: Linux (Raspbian) Commands is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?