* any string of characters
? any one character
[set] any character in a set
[!set] any character not in a set
Brace Expansion
echo b{ed,olt,ar,oob}s
beds bolts bars boobs
{a..c} expands to a b c
{1..4} exapnds to 1 2 3 4
ls *.[c,h,o]
ls *.c *.h *.o
ls -l *.{a..d}
ls -l *.a *.b *.c *.d
Commong data filtering utilities
cat copy input to output
grep search for strings in input
sort sort lines in the input
cut extract columns from input
sed perform editing operations on input
tr translate characters in the input to other characters
If you put a command into backgroups with &, you can use the jobs command to view running background jobs
~ home directory
` command substitution
# comment
$ variable expression
& background job
* string wildcard
( start subshell
) end subshell
\ quote next character
| pipe
[ start character set wildcard
] end characger set wildcart
{ start command block
} end command block
; shell command separator
' strong quote
<"> weak quote
< input redirect
> output redirect
/ pathname seperator
? single character wildcard
! pipeline logical not
To include quotes in an output, use
echo he said \"hello\" or
echo "he said \"hello\""
Not the same with single quotes
echo he said \'hello\' will work, but
echo 'he said \'hello\'' won't work
This doesn't work for single quotes.
You have to do:
echo 'he said '\''hello'\'
The first ' in '\''end the quoted string.
The \' inserts the literal single quote, them the next ' starts another quotes string
This can be done two ways and you get different results
The single quote method captures the return in the string.
The backslash method treats is like was no return
$ echo 'go and
> get
> fucked'
go and
get
fucked
$ echo go and \
> get \
> fucked
go and get fucked
key stty name function
ctrl-c intr stop current command
ctrl-d eof end of input
ctrl-\ quit stop current command if ctrl-c doesn't work
ctrl-h erase backspace
ctrl-m return
ctrl-s stop halt output to screen
ctrl-q restart output to screen
ctrl-u kill erase entire command line
ctrl-z susp suspend current command
command1 && command2 only run command2 if command1 runs successfully
command1 || command2 only run command2 if command1 exits with an error
set -u
set -o pipefail
Good options to put in any script.
set -u means that an attempt to reference a blank variable will kill the script with an error
set -o pipefail means that any error that happens in a piped command is passed up the pipe to the script, which will then get the error code
If you want to have more than one condition in an if, each condition should be grouped in brackets or use double brackets.
#This won't work
if [ "$v" == 1 && "$x" == 2 ]; then
#Use
if [ "$v" == 1 ] && [ "$x" == 2 ]; then
#or use double brackets. Apparently this is the preferred way
if [[ "$v" == 1 && "$x" == 2 ]]; then