This is a draft cheat sheet. It is a work in progress and is not finished yet.
Behavior
>& |
Mix stdout and stderr |
$? |
Exit code of last command |
type -a |
Command info (shell builtin/location/reserved word) |
${fooBar} |
Equivalent to $fooBar |
${foo//search/replace} |
Replace substring |
"$foo ${foo}" |
Interpolation |
var=$(ls) |
Capture stdout of ls and store in var |
echo "$num42+2" |
42+2 |
echo "$((num42+2))" |
44 # interpret arithmetic |
Control flow
IFS="," |
have $foo expand using "," instead of " " |
|
|
Test
[ -n "$a" ] |
Nonzero length |
[ -x "$a" ] |
Executable |
[ -d "$a" ] |
Is directory |
Misc
bash -x |
Print each command with args before execution |
~foo/ |
Home directory of user foo |
find app/controllers/*/.rb -type f -exec wc -l {} \; |
For each ruby file, list line count |
Streams
buzz 1> okay.txt 2> err.txt |
Redirect stdout into okay, stderr into err |
2>&1 |
Redirect stderr into stdout |
|
|
Cut
cut -d: -f1,2 |
select columns 1,2 separated by : |
|