mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 13:42:11 +01:00
commit
02f79ddd13
13 changed files with 78 additions and 3 deletions
|
@ -42,7 +42,7 @@ from docopt import docopt
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# parse the command-line options
|
# parse the command-line options
|
||||||
options = docopt(__doc__, version='cheat 2.2.1')
|
options = docopt(__doc__, version='cheat 2.2.2')
|
||||||
|
|
||||||
# list directories
|
# list directories
|
||||||
if options['--directories']:
|
if options['--directories']:
|
||||||
|
|
5
cheat/cheatsheets/alias
Normal file
5
cheat/cheatsheets/alias
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# 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'
|
8
cheat/cheatsheets/cat
Normal file
8
cheat/cheatsheets/cat
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Display the contents of a file
|
||||||
|
cat /path/to/foo
|
||||||
|
|
||||||
|
# Display contents with line numbers
|
||||||
|
cat -n /path/to/foo
|
||||||
|
|
||||||
|
# Display contents with line numbers (blank lines excluded)
|
||||||
|
cat -b /path/to/foo
|
11
cheat/cheatsheets/cp
Normal file
11
cheat/cheatsheets/cp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Create a copy of a file
|
||||||
|
cp ~/Desktop/foo.txt ~/Downloads/foo.txt
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Create a backup file with date
|
||||||
|
cp foo.txt{,."$(date +%Y%m%d-%H%M%S)"}
|
|
@ -36,3 +36,6 @@ curl --limit-rate 1000B -O http://path.to.the/file
|
||||||
|
|
||||||
# Get your global IP
|
# Get your global IP
|
||||||
curl httpbin.org/ip
|
curl httpbin.org/ip
|
||||||
|
|
||||||
|
# Get only the HTTP status code
|
||||||
|
curl -o /dev/null -w '%{http_code}\n' -s -I URL
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt}
|
# 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 first iteration, we read 512 Bytes.
|
||||||
# Note: At the second 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'
|
# 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
|
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
|
||||||
|
|
5
cheat/cheatsheets/export
Normal file
5
cheat/cheatsheets/export
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Calling export with no arguments will show current shell attributes
|
||||||
|
export
|
||||||
|
|
||||||
|
# Create new environment variable
|
||||||
|
export VARNAME="value"
|
5
cheat/cheatsheets/kill
Normal file
5
cheat/cheatsheets/kill
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Kill a process gracefully
|
||||||
|
kill -15 <process id>
|
||||||
|
|
||||||
|
# Kill a process forcefully
|
||||||
|
kill -9 <process id>
|
14
cheat/cheatsheets/mv
Normal file
14
cheat/cheatsheets/mv
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Move a file from one place to another
|
||||||
|
mv ~/Desktop/foo.txt ~/Documents/foo.txt
|
||||||
|
|
||||||
|
# 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
|
2
cheat/cheatsheets/pwd
Normal file
2
cheat/cheatsheets/pwd
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Show the absolute path of your current working directory on the filesystem
|
||||||
|
pwd
|
18
cheat/cheatsheets/wc
Normal file
18
cheat/cheatsheets/wc
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Count the number of words (file or STDIN)
|
||||||
|
wc -w /path/to/foo.txt
|
||||||
|
cat /path/to/foo.txt | wc -w
|
||||||
|
|
||||||
|
# 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
|
|
@ -10,3 +10,7 @@ find -name *.pdf | xargs -I{} rm -rf '{}'
|
||||||
# -n1 => One file by one file. ( -n2 => 2 files by 2 files )
|
# -n1 => One file by one file. ( -n2 => 2 files by 2 files )
|
||||||
|
|
||||||
find -name *.pdf | xargs -I{} -n1 echo '&{}='
|
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
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'cheat',
|
name = 'cheat',
|
||||||
version = '2.2.1',
|
version = '2.2.2',
|
||||||
author = 'Chris Lane',
|
author = 'Chris Lane',
|
||||||
author_email = 'chris@chris-allen-lane.com',
|
author_email = 'chris@chris-allen-lane.com',
|
||||||
license = 'GPL3',
|
license = 'GPL3',
|
||||||
|
|
Loading…
Reference in a new issue