Skip to main content
Chemistry LibreTexts

3: File and User Management

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

    This page is being built

     

     

     

     

    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
      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/myscript.sh
      
    • 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
      pwd
      
    • reboot
    sudo reboot
    

     

    • rm <file>:  Deletes file, to delete a folder use -rf (recursive force)
      rm myscipt.sh
      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
      tree
      
    • 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)

    Configuration

    • ipconfig:  Diplays current IP donfiguation  (ip a) is shortcut
      ifconfig
      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
      ping 111.111.1.1
      

    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@111.111.1.1
      

    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)
      htop
      

       

    • 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
    
    clipboard_e9b0fee767107ea7c223646f80516138d.png

    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 

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

    d

    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: File and User Management is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?