GNU/Linux.guru
Document thumbnail.
Download: [PDF|HTML|ConTEXt|GitHub]

Bourne-Again SHell and Linux CLI

Set interpreter: #!/bin/bash    Remarks: # this is comment

Interactive control

Action set -o vi set -o emacs
vi-command mode ( C)  Esc
Previous/next command in history  jC / kC  Ctrl+p / Ctrl+n
PageUp / PageDown
Automatic fill of file name  EscEscC  Tab
List of all matches  Esc=  TabTab
Horizontal move in command line  hC / lC  Ctrl+b / Ctrl+f, /
Jump to line begin/end  ^C / $C  Ctrl+a / Ctrl+e
Backward/forward history search  /C / ?C  Ctrl+r / Ctrl+s
Delete word to the end/begin  dwC / dbC  Esc d / Esc h
Delete text from cursor to the line end/begin  d$C / d^C  Ctrl+k / Ctrl+u

Command line history

Help and manuals

Debugging

Run a script as: bash option script and its parameters

Variables, arrays and hashes

Strings

Embedded variables

Script command line parameters

Read options from command line

 while getopts "a:b" opt; do case $opt in
      a) echo a = $OPTARG ;;
      b) echo b ;;
      \?) echo "Unknown parameter!" ;;
esac; done
shift $(($OPTIND - 1)); echo "Last: $1" 

Control expressions

Redirections and pipes

Input for interactive programs (here documents)

./program <<  EOF      ./program <<-'EOF' # suppress tabulators
Input1                      Input1
Input2                      Input2
EOF                         EOF

Process file line by line

cat file.txt | (while read L; do echo "$L"; done)

Evaluating mathematical expressions

Screen output

Process management

Time and process planning

File operations

File name wildchars: ? a char; * zero or more chars; [set] one or more given chars, interval [0-9] [a-z], [A-Z]; [!set], [^set] none of chars.

Work with file content

Search

Users and permissions

System utilities

Disk partitions

System utilization

Networking