Skip to main content
Chemistry LibreTexts

4: Operating System Commands

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

    Operating System Commands

     

    date

    date
    date +%m-%d-%y
    

     

    df - free space

    Display Partitions (free space)

    To make the output easier to understand (in Kilobytes, Megabytes and Gigabytes), use the option -h (human-readable) with the df command

    To know the storage usage of each folder, use the command:

    df
    df -h
    
    Output:

    clipboard_e8a47ec3f08da23c3cd6832bd110975f0.png

     

    du - disk usage

    To know how much storage has been used from the disk, use the command:

    • du : disk usage
    • du
      du/home/pi 
      

      for a specific directory (home/pi)

    Be careful!

    By using the du command by itself, be ready to get a big number of logs with all the files that exist on your disk!

    We will be discussing the options to get precise outputs using the du command in the following part.

     

    To know the storage usage of each folder, use the command:

    du -h --max-depth=1 ./
    
    Output:

    clipboard_e87e90398124ed7d93498b2932f359955.png

     

    dmesg

    displays kernel related messages about hardware, device drivers, initialization and bootup issues

     

    In this activity we will check bootup processes and errors

    dmesg
    
    Output:

    clipboard_e3d60125c492396051bd32fd67656ad76.png

     

    free

    To know how much RAM the server has, use the command:

    • free
    • free -b : b is for bytes
    • free -k : k is for kilo-bytes
    • free -m : m is for mega-bytes
    • free -g : g is for giga_bytes
    free
    free -b
    
    Output:

    clipboard_eaa53f5966b654ea0f106497afafcc1b7.png

     

    htop

     

    Monitor running processes

     

    In this activity we will check bootup processes and errors (you need to use ctrl c to terminate

    htop
    
    Output:

    clipboard_e9cb9ce9ff093539a730eb7ba87c3af43.png

     

    kill/killall

    kills a specific process by its process id, which you get with the ps command

    ps
    kill ###(the process ID of the process you want to kill)
    

     

    lscpu

    list number of cpus

    lscpu
    
    Output:

    clipboard_e2b3e7d2c83c1ec792a31e831da90c99f.png

     

    ps

    To display the currently running processes, use the command:

    • ps : process status: produces a snapshot of the running processes.
    ps
    
    Output:

    clipboard_e8415cc486999dae1852130d52ff35c79.png

    The output contains a list of the running processes under 4 columns:

    - PID: the process identification number

    - TTY: the terminal name

    - TIME: the running time

    - CMD: the name of the command that launches the process

    Options that can be used with the ps command:

    • ps -a : lists all the running processes of all the users
    • ps -u : lists additional information (memory usage, CPU usage percentage, process state code, and process owner)

    reboot

    sudo reboot
    

    shutdown

    sudo shutdown -h now 
    sudo shutdown -h 20:00
    

    -h switch halts processes, and the 20:00 specifies the time for shutdown

    top

    resource-usage of processes

    top
    
    Output:

    clipboard_e43eec1706420eb5bb0da152da3d03133.png

    Note

    Unlike the ps command, the top command output updates periodically; You will see real-time updates for running times and CPU usage.

    The output of the top command is a shell that allows the user to move through processes and interact with them. 

    Interacting with a process is done by the keys:

    • k : kills the process
    • M : sorts the list by memory usage
    • N : sorts the list by the process identification numbers
    • r : changes the priority of the process
    • d : changes the refresh time interval
    • c : displays the path of the process

     

     


    4: Operating System Commands is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?