From aa9403d43294d3a71a27d198a981efd0109b24f3 Mon Sep 17 00:00:00 2001 From: shanahanjrs Date: Sun, 12 Feb 2017 22:11:45 -0500 Subject: [PATCH 1/8] Created cheatsheets for alias, cat, cp, export, kill, mv, pwd, and wc --- cheat/cheatsheets/alias | 11 +++++++++++ cheat/cheatsheets/cat | 10 ++++++++++ cheat/cheatsheets/cp | 14 ++++++++++++++ cheat/cheatsheets/export | 5 +++++ cheat/cheatsheets/kill | 7 +++++++ cheat/cheatsheets/mv | 7 +++++++ cheat/cheatsheets/pwd | 3 +++ cheat/cheatsheets/wc | 7 +++++++ 8 files changed, 64 insertions(+) create mode 100644 cheat/cheatsheets/alias create mode 100644 cheat/cheatsheets/cat create mode 100644 cheat/cheatsheets/cp create mode 100644 cheat/cheatsheets/export create mode 100644 cheat/cheatsheets/kill create mode 100644 cheat/cheatsheets/mv create mode 100644 cheat/cheatsheets/pwd create mode 100644 cheat/cheatsheets/wc diff --git a/cheat/cheatsheets/alias b/cheat/cheatsheets/alias new file mode 100644 index 0000000..f9c515a --- /dev/null +++ b/cheat/cheatsheets/alias @@ -0,0 +1,11 @@ +# alias - Creates an alias of a command +*Stick these in your .bashrc/.bash_profile for permenant use, otherwise lost on re-entry + +alias ll='ls -l' +alias lll='ls -al' +alias vi='vim' +alias ..='cd ..' +alias c='clear' +alias rkhunter='rkhunter --versioncheck --update --autox --skip-keypress --check' + +Running just `alias' will show your current aliases. diff --git a/cheat/cheatsheets/cat b/cheat/cheatsheets/cat new file mode 100644 index 0000000..c80b75f --- /dev/null +++ b/cheat/cheatsheets/cat @@ -0,0 +1,10 @@ +# cat - concatenate and print files +cat [-benstuv] [filename] + +-b : Number non blank lines (1 indexed) +-e : Display non printing chars +-n : Number output (1 indexed) +-s : Single spaced output +-t : Display non printing chars (Tab as `^I') +-u : Disable output buffering +-v : Display all non printing chars no matter what diff --git a/cheat/cheatsheets/cp b/cheat/cheatsheets/cp new file mode 100644 index 0000000..f1de317 --- /dev/null +++ b/cheat/cheatsheets/cp @@ -0,0 +1,14 @@ +# cp - copy. Copies a file or directory +cp [-a, -f, -H, -i, -L, -n, -p, -P, -R, -X] [-v] [source] [target] + +-a : Same as -pPR +-f : Force +-H : Follow sym links +-i : Prompt before overwrite +-L : If -R, follow sym links +-n : Do not overwrite +-P : If -R, Do not follow sym links (Default) +-p : Preserve meta data +-R : Recursive (cp directories) +-X : Do not copy extended attributes or resource forks +-v : Verbose diff --git a/cheat/cheatsheets/export b/cheat/cheatsheets/export new file mode 100644 index 0000000..34223a0 --- /dev/null +++ b/cheat/cheatsheets/export @@ -0,0 +1,5 @@ +# Export makes a variable something that will be included in child process environments +export VARNAME="value" + +# Calling export with no arguments will show current shell attributes +export diff --git a/cheat/cheatsheets/kill b/cheat/cheatsheets/kill new file mode 100644 index 0000000..836c8ec --- /dev/null +++ b/cheat/cheatsheets/kill @@ -0,0 +1,7 @@ +# kill - Kills a process + +# Kill gracefully +kill -15 [PID] + +# Force kill (*Only use if -15 does not work first, this is dirty*) +kill -9 [PID] diff --git a/cheat/cheatsheets/mv b/cheat/cheatsheets/mv new file mode 100644 index 0000000..c31de4c --- /dev/null +++ b/cheat/cheatsheets/mv @@ -0,0 +1,7 @@ +# mv - move. Moves a file or directory +mv [-f, -i, -n] [-v] [source] [target] + +-f : No prompt before overwriting something in target destination. Overrides any previous -i or -n args. +-i : Prompt before overwriting something. Overrides any previous -f or -n args. +-n : Do not overwrite anything. Overrides any previous -f or -i args. +-v : Verbose diff --git a/cheat/cheatsheets/pwd b/cheat/cheatsheets/pwd new file mode 100644 index 0000000..ab7f8fb --- /dev/null +++ b/cheat/cheatsheets/pwd @@ -0,0 +1,3 @@ +# Print Working Directory +# The `pwd' command will show you the absolute path of your current directory on the filesystem +pwd diff --git a/cheat/cheatsheets/wc b/cheat/cheatsheets/wc new file mode 100644 index 0000000..99c3fa9 --- /dev/null +++ b/cheat/cheatsheets/wc @@ -0,0 +1,7 @@ +# wc - word count (or lines, characters, or bytes) +wc [-clmw] [output] + +-c : Number of bytes (cancels -m opt) +-l : Number of lines +-m : Number of characters (cancels -c opt) +-w : Number of words From e5bf9146fe43a2669ade18605b71bcb66ab26b0f Mon Sep 17 00:00:00 2001 From: shanahanjrs Date: Tue, 12 Sep 2017 23:11:38 -0400 Subject: [PATCH 2/8] Fixed cheat sheets to conform to the standard style more closely --- cheat/cheatsheets/alias | 12 +++--------- cheat/cheatsheets/cat | 16 +++++++--------- cheat/cheatsheets/cp | 20 +++++++------------- cheat/cheatsheets/export | 6 +++--- cheat/cheatsheets/kill | 10 ++++------ cheat/cheatsheets/mv | 19 +++++++++++++------ cheat/cheatsheets/pwd | 3 +-- cheat/cheatsheets/wc | 23 +++++++++++++++++------ 8 files changed, 55 insertions(+), 54 deletions(-) diff --git a/cheat/cheatsheets/alias b/cheat/cheatsheets/alias index f9c515a..9bd98c1 100644 --- a/cheat/cheatsheets/alias +++ b/cheat/cheatsheets/alias @@ -1,11 +1,5 @@ -# alias - Creates an alias of a command -*Stick these in your .bashrc/.bash_profile for permenant use, otherwise lost on re-entry +# Show a list of your current shell aliases +alias +# Map `ll` to `ls -l` (Can be used per session or put inside a shell config file) alias ll='ls -l' -alias lll='ls -al' -alias vi='vim' -alias ..='cd ..' -alias c='clear' -alias rkhunter='rkhunter --versioncheck --update --autox --skip-keypress --check' - -Running just `alias' will show your current aliases. diff --git a/cheat/cheatsheets/cat b/cheat/cheatsheets/cat index c80b75f..69a25d0 100644 --- a/cheat/cheatsheets/cat +++ b/cheat/cheatsheets/cat @@ -1,10 +1,8 @@ -# cat - concatenate and print files -cat [-benstuv] [filename] +# Display the contents of a file +cat /path/to/foo --b : Number non blank lines (1 indexed) --e : Display non printing chars --n : Number output (1 indexed) --s : Single spaced output --t : Display non printing chars (Tab as `^I') --u : Disable output buffering --v : Display all non printing chars no matter what +# Display contents with line numbers +cat -n /path/to/foo + +# Display contents with line numbers (blank lines excluded) +cat -b /path/to/foo diff --git a/cheat/cheatsheets/cp b/cheat/cheatsheets/cp index f1de317..3c0e246 100644 --- a/cheat/cheatsheets/cp +++ b/cheat/cheatsheets/cp @@ -1,14 +1,8 @@ -# cp - copy. Copies a file or directory -cp [-a, -f, -H, -i, -L, -n, -p, -P, -R, -X] [-v] [source] [target] +# Create a copy of a file +cp ~/Desktop/foo.txt ~/Downloads/foo.txt --a : Same as -pPR --f : Force --H : Follow sym links --i : Prompt before overwrite --L : If -R, follow sym links --n : Do not overwrite --P : If -R, Do not follow sym links (Default) --p : Preserve meta data --R : Recursive (cp directories) --X : Do not copy extended attributes or resource forks --v : Verbose +# Create a copy of a directory +cp -r ~/Desktop/cruise_pics/ ~/Pictures/ + +# Create a copy but ask to overwrite if the destination file already exists +cp -i ~/Desktop/foo.txt ~/Documents/foo.txt diff --git a/cheat/cheatsheets/export b/cheat/cheatsheets/export index 34223a0..14d3d71 100644 --- a/cheat/cheatsheets/export +++ b/cheat/cheatsheets/export @@ -1,5 +1,5 @@ -# Export makes a variable something that will be included in child process environments -export VARNAME="value" - # Calling export with no arguments will show current shell attributes export + +# Create new environment variable +export VARNAME="value" diff --git a/cheat/cheatsheets/kill b/cheat/cheatsheets/kill index 836c8ec..d80510e 100644 --- a/cheat/cheatsheets/kill +++ b/cheat/cheatsheets/kill @@ -1,7 +1,5 @@ -# kill - Kills a process +# Kill a process gracefully +kill -15 -# Kill gracefully -kill -15 [PID] - -# Force kill (*Only use if -15 does not work first, this is dirty*) -kill -9 [PID] +# Kill a process forcefully +kill -9 diff --git a/cheat/cheatsheets/mv b/cheat/cheatsheets/mv index c31de4c..a3f5f19 100644 --- a/cheat/cheatsheets/mv +++ b/cheat/cheatsheets/mv @@ -1,7 +1,14 @@ -# mv - move. Moves a file or directory -mv [-f, -i, -n] [-v] [source] [target] +# Move a file from one place to another +mv ~/Desktop/foo.txt ~/Documents/foo.txt --f : No prompt before overwriting something in target destination. Overrides any previous -i or -n args. --i : Prompt before overwriting something. Overrides any previous -f or -n args. --n : Do not overwrite anything. Overrides any previous -f or -i args. --v : Verbose +# Move a file from one place to another and automatically overwrite if the destination file exists +# (This will override any previous -i or -n args) +mv -f ~/Desktop/foo.txt ~/Documents/foo.txt + +# Move a file from one place to another but ask before overwriting an existing file +# (This will override any previous -f or -n args) +mv -i ~/Desktop/foo.txt ~/Documents/foo.txt + +# Move a file from one place to another but never overwrite anything +# (This will override any previous -f or -i args) +mv -n ~/Desktop/foo.txt ~/Documents/foo.txt diff --git a/cheat/cheatsheets/pwd b/cheat/cheatsheets/pwd index ab7f8fb..f672c88 100644 --- a/cheat/cheatsheets/pwd +++ b/cheat/cheatsheets/pwd @@ -1,3 +1,2 @@ -# Print Working Directory -# The `pwd' command will show you the absolute path of your current directory on the filesystem +# Show the absolute path of your current working directory on the filesystem pwd diff --git a/cheat/cheatsheets/wc b/cheat/cheatsheets/wc index 99c3fa9..c8d771e 100644 --- a/cheat/cheatsheets/wc +++ b/cheat/cheatsheets/wc @@ -1,7 +1,18 @@ -# wc - word count (or lines, characters, or bytes) -wc [-clmw] [output] +# Count the number of words (file or STDIN) +wc -w /path/to/foo.txt +cat /path/to/foo.txt | wc -w --c : Number of bytes (cancels -m opt) --l : Number of lines --m : Number of characters (cancels -c opt) --w : Number of words +# Count the number of lines (file or STDIN) +wc -l /path/to/foo.txt +cat /path/to/foo.txt | wc -l + +# Count the number of bytes (file or STDIN) +wc -c /path/to/foo.txt +cat /path/to/foo.txt | wc -c + +# Count files and directories at a given location +ls -l | wc -l + +# If you ever use `wc` in a shell script and need to compare the output with an int you can +# clean the output (wc returns extra characters around the integer) by using xargs: +ls -l | wc -l | xargs From f8d2ce516ec6b0d467a25632c6b6b3b064fdfade Mon Sep 17 00:00:00 2001 From: ALJI Mohamed Date: Sat, 16 Sep 2017 22:04:10 +0100 Subject: [PATCH 3/8] Update dd There is a small error in this sample : **bs=BYTES** --> read and write up to BYTES bytes at a time **count=N** --> copy only N input blocks just inverse please --- cheat/cheatsheets/dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheat/cheatsheets/dd b/cheat/cheatsheets/dd index a557e13..88d7f4a 100644 --- a/cheat/cheatsheets/dd +++ b/cheat/cheatsheets/dd @@ -1,7 +1,7 @@ # Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt} # Note: At the first iteration, we read 512 Bytes. # Note: At the second iteration, we read 512 Bytes. -dd if=/dev/urandom of=/tmp/test.txt count=512 bs=2 +dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512 # Watch the progress of 'dd' dd if=/dev/zero of=/dev/null bs=4KB &; export dd_pid=`pgrep '^dd'`; while [[ -d /proc/$dd_pid ]]; do kill -USR1 $dd_pid && sleep 1 && clear; done From d7272c50c43d48c6ee2c051709a85fafdab1154a Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sat, 16 Sep 2017 23:15:15 -0400 Subject: [PATCH 4/8] v2.2.2 Added new cheatsheets. --- bin/cheat | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cheat b/bin/cheat index f48f069..00940d5 100755 --- a/bin/cheat +++ b/bin/cheat @@ -42,7 +42,7 @@ from docopt import docopt if __name__ == '__main__': # parse the command-line options - options = docopt(__doc__, version='cheat 2.2.1') + options = docopt(__doc__, version='cheat 2.2.2') # list directories if options['--directories']: diff --git a/setup.py b/setup.py index 514f806..499f340 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os setup( name = 'cheat', - version = '2.2.1', + version = '2.2.2', author = 'Chris Lane', author_email = 'chris@chris-allen-lane.com', license = 'GPL3', From aa4f6daf771c465073747644582b82495a6853c8 Mon Sep 17 00:00:00 2001 From: Michihito Shigemura Date: Wed, 4 Oct 2017 23:47:33 +0900 Subject: [PATCH 5/8] Add cheatsheet for cp backup file with date --- cheat/cheatsheets/cp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cheat/cheatsheets/cp b/cheat/cheatsheets/cp index 3c0e246..5e84c64 100644 --- a/cheat/cheatsheets/cp +++ b/cheat/cheatsheets/cp @@ -6,3 +6,6 @@ cp -r ~/Desktop/cruise_pics/ ~/Pictures/ # Create a copy but ask to overwrite if the destination file already exists cp -i ~/Desktop/foo.txt ~/Documents/foo.txt + +# Create a backup file with date +cp foo.txt{,."$(date +%Y%m%d-%H%M%S)"} \ No newline at end of file From 4319b8e69922676acc5c596fd2ad98c739377458 Mon Sep 17 00:00:00 2001 From: Michihito Shigemura Date: Tue, 24 Oct 2017 22:23:36 +0900 Subject: [PATCH 6/8] Add curl cheatsheet: Get only the HTTP status code curl -o /dev/null -w '%{http_code}\n' -s -I URL --- cheat/cheatsheets/curl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cheat/cheatsheets/curl b/cheat/cheatsheets/curl index 52f53ea..c8c281f 100644 --- a/cheat/cheatsheets/curl +++ b/cheat/cheatsheets/curl @@ -36,3 +36,6 @@ curl --limit-rate 1000B -O http://path.to.the/file # Get your global IP curl httpbin.org/ip + +# Get only the HTTP status code +curl -o /dev/null -w '%{http_code}\n' -s -I URL From 2c10955690012c25a5d20893cf9549f1e63fe580 Mon Sep 17 00:00:00 2001 From: Michihito Shigemura Date: Fri, 27 Oct 2017 00:11:27 +0900 Subject: [PATCH 7/8] Add cheatsheet for xargs --no-run-if-empty --- cheat/cheatsheets/xargs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cheat/cheatsheets/xargs b/cheat/cheatsheets/xargs index 44bf20a..a1391f3 100644 --- a/cheat/cheatsheets/xargs +++ b/cheat/cheatsheets/xargs @@ -10,3 +10,7 @@ find -name *.pdf | xargs -I{} rm -rf '{}' # -n1 => One file by one file. ( -n2 => 2 files by 2 files ) find -name *.pdf | xargs -I{} -n1 echo '&{}=' + +# If find returns no result, do not run rm +# This option is a GNU extension. +find -name "*.pdf" | xargs --no-run-if-empty rm From d12718b8c46ad726fbb32e56b6beffd308eb1d88 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sun, 19 Nov 2017 08:09:37 -0500 Subject: [PATCH 8/8] `cp` edit Appended missing newline to end of `cp` cheatsheet. --- cheat/cheatsheets/cp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheat/cheatsheets/cp b/cheat/cheatsheets/cp index 5e84c64..7003e2c 100644 --- a/cheat/cheatsheets/cp +++ b/cheat/cheatsheets/cp @@ -8,4 +8,4 @@ cp -r ~/Desktop/cruise_pics/ ~/Pictures/ cp -i ~/Desktop/foo.txt ~/Documents/foo.txt # Create a backup file with date -cp foo.txt{,."$(date +%Y%m%d-%H%M%S)"} \ No newline at end of file +cp foo.txt{,."$(date +%Y%m%d-%H%M%S)"}