Merge pull request #1371 from synbit/master

bash cheat sheet
master
Zaahir Moolla 2015-08-19 00:58:54 -04:00
commit 15d0985090
1 changed files with 463 additions and 0 deletions

View File

@ -0,0 +1,463 @@
{
"id": "bash_cheat_sheet",
"name": "Bash",
"description": "Bourne-Again shell",
"metadata": {
"sourceName": "Bash Reference Manual",
"sourceUrl": "https://www.gnu.org/software/bash/"
},
"section_order": [
"Lingo",
"Shortcuts",
"Special Variables",
"Standard File Descriptors",
"Arithmetic Operators",
"IO Redirection",
"Expansion And Other Operators",
"Exit Statuses",
"Auto-Completion",
"Misc"
],
"sections": {
"Lingo": [
{
"key": "C",
"val": "Ctrl"
},
{
"key": "M",
"val": "Meta Key (Alt or ESC)"
}
],
"Shortcuts": [
{
"key": "C-c",
"val": "Interrupt running process"
},
{
"key": "C-z",
"val": "Suspend running process"
},
{
"key": "C-d",
"val": "Exit from current shell"
},
{
"key": "C-l",
"val": "Clear Screen"
},
{
"key": "C-a",
"val": "Move at the start of the line"
},
{
"key": "C-e",
"val": "Move at the end of the line"
},
{
"key": "M-←",
"val": "Move backward by a word"
},
{
"key": "M-b",
"val": "Move backward by a word (alternative)"
},
{
"key": "M-→",
"val": "Move forward by a word"
},
{
"key": "M-f",
"val": "Move forward by a word (alternative)"
},
{
"key": "[C-x], [C-x]",
"val": "Move cursor between start of line and current position"
},
{
"key": "M-t",
"val": "Swap the last two words before the cursor"
},
{
"key": "C-t",
"val": "Swap the last two characters before the cursor"
},
{
"key": "M-Backspace",
"val": "Delete a word (backward)"
},
{
"key": "C-w",
"val": "Delete a word (backward) (alternative)"
},
{
"key": "M-d",
"val": "Delete a word (forward)"
},
{
"key": "C-h",
"val": "Delete one character backward (same as Backspace)"
},
{
"key": "C-k",
"val": "Kill from cursor to the end of line"
},
{
"key": "C-u",
"val": "Kill from cursor to the beginning of line"
},
{
"key": "M-u",
"val": "Upper-case from cursor to the end of word"
},
{
"key": "M-l",
"val": "Lower-case from cursor to the end of word"
},
{
"key": "M-c",
"val": "Capitalize word (from cursor position)"
},
{
"key": "C-y",
"val": "Paste"
},
{
"key": "C-_",
"val": "Undo"
},
{
"key": "M-r",
"val": "Revert to original command (before editing it)"
},
{
"key": "C-p",
"val": "Get previous command"
},
{
"key": "C-n",
"val": "Get next command"
},
{
"key": "[C-r], [<pattern>]",
"val": "Search previous command containing <pattern>"
},
{
"key": "M-.",
"val": "Insert last argument of last command"
},
{
"key": "[M-<N>], [C-M-y]",
"val": "Get Nth argument of previous command (N=0 gives the command)"
},
{
"key": "M-<",
"val": "Insert oldest command from history"
},
{
"key": "[C-x], [C-v]",
"val": "Show bash version"
},
{
"key": "[C-x], [C-e]",
"val": "Edit current line with ${EDITOR}"
}
],
"Special Variables": [
{
"key": "!$",
"val": "Last argument of last command"
},
{
"key": "$<N>",
"val": "Nth argument of current process (positional parameter)"
},
{
"key": "$#",
"val": "Number of arguments given to current process"
},
{
"key": "$@",
"val": "Command line arguments for current process"
},
{
"key": "$*",
"val": "Without quotes, same as '$@'"
},
{
"key": "\"$*\"",
"val": "Command line arguments for current process, expanded to a single argument"
},
{
"key": "$0",
"val": "The name of the shell program"
},
{
"key": "$?",
"val": "Exit code of previous command"
},
{
"key": "$$",
"val": "PID of current shell or script"
},
{
"key": ":",
"val": "Dummy placeholder (produces no output)"
},
{
"key": "!-<N>",
"val": "Execute Nth command from history"
},
{
"key": "!!",
"val": "Execute last command"
},
{
"key": "!<string>",
"val": "Execute last command starting with <string>"
}
],
"Standard File Descriptors": [
{
"key": "0",
"val": "stdin"
},
{
"key": "1",
"val": "stdout"
},
{
"key": "2",
"val": "stderr"
}
],
"Arithmetic Operators": [
{
"key": "+",
"val": "Addition"
},
{
"key": "-",
"val": "Subtraction"
},
{
"key": "++",
"val": "Increment"
},
{
"key": "--",
"val": "Decrement"
},
{
"key": "*",
"val": "Multiplication"
},
{
"key": "/",
"val": "Division"
},
{
"key": "**",
"val": "Exponentiation"
},
{
"key": "<<",
"val": "Bit-shift left"
},
{
"key": ">>",
"val": "Bit-shift right"
},
{
"key": "<",
"val": "Comparison (less than)"
},
{
"key": "-lt",
"val": "Comparison (less than) (alternative)"
},
{
"key": "<=",
"val": "Comparison (less than or equal)"
},
{
"key": "-le",
"val": "Comparison (less than or equal) (alternative)"
},
{
"key": ">",
"val": "Comparison (greater than)"
},
{
"key": "-gt",
"val": "Comparison (greater than) (alternative)"
},
{
"key": ">=",
"val": "Comparison (greater than or equal)"
},
{
"key": "-ge",
"val": "Comparison (greater than or equal) (alternative)"
},
{
"key": "==",
"val": "Comparison (equal)"
},
{
"key": "!=",
"val": "Comparison (not equal)"
},
{
"key": "&",
"val": "Bitwise AND"
},
{
"key": "^",
"val": "Bitwise exclusive OR"
},
{
"key": "|",
"val": "Bitwise OR"
},
{
"key": "&&",
"val": "Logical AND"
},
{
"key": "||",
"val": "Logical OR"
}
],
"IO Redirection": [
{
"key": "cmd > file",
"val": "Send cmd output to file (overwrite)"
},
{
"key": "cmd >> file",
"val": "Send cmd output to file (append)"
},
{
"key": "cmd < file",
"val": "Contents of file are passed to cmd's stdin"
},
{
"key": "cmd1 | cmd2",
"val": "Output of cmd1 is passed to cmd2's stdin"
},
{
"key": "cmd &> file",
"val": "Redirect both stdout and stderr to file (overwrite)"
},
{
"key": "cmd &>> file",
"val": "Redirect both stdout and stderr to file (append)"
},
{
"key": "cmd >&n",
"val": "Send cmd's stdout to file descriptor n"
},
{
"key": "cmd m>&n",
"val": "Same as above except that output that would normally go to file descriptor m, will also go to n"
},
{
"key": "cmd <&n",
"val": "File descriptor n becomes stdin for cmd"
},
{
"key": "cmd m<&n",
"val": "Same as above except that stdin that would normally come from file descriptor m, will now come from n"
},
{
"key": "cmd >&-",
"val": "Close stdout"
},
{
"key": "cmd <&-",
"val": "Close stdin"
}
],
"Expansion And Other Operators": [
{
"key": "${var:-val}",
"val": "If $var exists and isn't NULL, return its value; otherwise return val"
},
{
"key": "${var:=val}",
"val": "If $var exists and isn't NULL, return its value; otherwise set it to val and then return its value"
},
{
"key": "${var:?val}",
"val": "If $var exists and isn't NULL, return its value; otherwise return 'var: val' and abort"
},
{
"key": "${var:?}",
"val": "If $var exists and isn't NULL, return its value; otherwise return 'var: parameter null or not set' and abort"
},
{
"key": "${var:+val}",
"val": "If $var exists and isn't NULL, return val; otherwise return NULL"
},
{
"key": "$((...))",
"val": "Arithmetic Expansion"
},
{
"key": "${#var}",
"val": "String length operator"
}
],
"Exit Statuses": [
{
"key": "0",
"val": "Success"
},
{
"key": "!=0",
"val": "Failure"
}
],
"Auto-Completion": [
{
"key": "TAB",
"val": "Auto-complete (hit twice when ambiguous)"
},
{
"key": "[~], [TAB] [TAB]",
"val": "Display all users from /etc/passwd"
},
{
"key": "[$], [TAB] [TAB]",
"val": "Display all system variables"
},
{
"key": "[<string>], [M-/]",
"val": "Auto-complete/display files and directories starting with <string>"
},
{
"key": "[<string>], [M-?]",
"val": "Display commands starting with <string>"
},
{
"key": "M-*",
"val": "Insert all possible completions"
}
],
"Misc": [
{
"key": "a=$(cmd)",
"val": "$a now holds cmd's output"
},
{
"key": "a=`cmd`",
"val": "$a now holds cmd's output (alternative)"
},
{
"key": "cmd &",
"val": "Execute cmd in the background (fork)"
}
]
}
}