A simple bash cheat sheet
|
>&
|
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
|
|
IFS=","
|
have $foo expand using "," instead of " "
|
|
[ -n "$a" ]
|
Nonzero length
|
|
[ -x "$a" ]
|
Executable
|
|
[ -d "$a" ]
|
Is directory
|
|
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
|
|
buzz 1> okay.txt 2> err.txt
|
Redirect stdout into okay, stderr into err
|
|
2>&1
|
Redirect stderr into stdout
|
|
cut -d: -f1,2
|
select columns 1,2 separated by :
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.