Acknowledgment

This lecture note is based on Dr. Hua Zhou’s 2018 Winter Statistical Computing course notes available at http://hua-zhou.github.io/teaching/biostatm280-2018winter/index.html.

Unix

Brief history

Unix-like OSes

The Unix Philosophy

Write programs that do one thing and do it well. Write programs to work together and that encourage open standards. Write programs to handle text streams, because that is a universal interface.

  • Doug McIlory, the Bell System Technical Journal (1978)

Modularity

  • The Unix shell (we’ll learn about this shortly) was designed to allow users to easily build complex workflows by interfacing smaller modular programs together.
    • wget | awk | grep | sort | uniq | plot
  • An alternative approach is to write a single complex program that takes raw data as input, and after hours of data processing, outputs publication figures and a final table of results.

Why Linux

Linux is the most common platform for scientific computing.

Distributions of Linux

Enter Linux

Source: https://uproxx.com/movies/enter-the-draon-trivia/


Linux shells

What is a shell?

  • A shell translates commands to OS instructions (similar to cmd.exe on Windows).

  • Most commonly used shells include bash, csh, tcsh, zsh, etc.

  • Sometimes a script or a command does not run simply because it’s written for another shell.

  • We mostly use bash shell commands in this class.


  • Determine the current shell:

    echo $SHELL
    ## /bin/bash
  • List available shells:

    cat /etc/shells
    ## # List of acceptable shells for chpass(1).
    ## # Ftpd will not allow users to connect who are not using
    ## # one of these shells.
    ## 
    ## /bin/bash
    ## /bin/csh
    ## /bin/ksh
    ## /bin/sh
    ## /bin/tcsh
    ## /bin/zsh

  • Change to another shell:

    exec bash -l

    The -l option indicates it should be a login shell.

  • Change your login shell permanently:

    chsh -s /bin/bash userid

    Then log out and log in.

Bash completion

Bash provides the following standard completion for the Linux users by default. Much less typing errors and time!

  • Pathname completion.

  • Filename completion.

  • Variablename completion: echo $[TAB][TAB].

  • Username completion: cd ~[TAB][TAB].

  • Hostname completion ssh username@[TAB][TAB].

  • It can also be customized to auto-complete other stuff such as options and command’s arguments. Google bash completion for more information.

Reference

Source: Amazon