diff --git a/cheat/cheatsheets/alias b/cheat/cheatsheets/alias new file mode 100644 index 0000000..9bd98c1 --- /dev/null +++ b/cheat/cheatsheets/alias @@ -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' diff --git a/cheat/cheatsheets/cat b/cheat/cheatsheets/cat new file mode 100644 index 0000000..69a25d0 --- /dev/null +++ b/cheat/cheatsheets/cat @@ -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 diff --git a/cheat/cheatsheets/cp b/cheat/cheatsheets/cp new file mode 100644 index 0000000..3c0e246 --- /dev/null +++ b/cheat/cheatsheets/cp @@ -0,0 +1,8 @@ +# 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 diff --git a/cheat/cheatsheets/export b/cheat/cheatsheets/export new file mode 100644 index 0000000..14d3d71 --- /dev/null +++ b/cheat/cheatsheets/export @@ -0,0 +1,5 @@ +# 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 new file mode 100644 index 0000000..d80510e --- /dev/null +++ b/cheat/cheatsheets/kill @@ -0,0 +1,5 @@ +# Kill a process gracefully +kill -15 + +# Kill a process forcefully +kill -9 diff --git a/cheat/cheatsheets/mv b/cheat/cheatsheets/mv new file mode 100644 index 0000000..a3f5f19 --- /dev/null +++ b/cheat/cheatsheets/mv @@ -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 diff --git a/cheat/cheatsheets/pwd b/cheat/cheatsheets/pwd new file mode 100644 index 0000000..f672c88 --- /dev/null +++ b/cheat/cheatsheets/pwd @@ -0,0 +1,2 @@ +# Show the absolute path of your current working directory on the filesystem +pwd diff --git a/cheat/cheatsheets/wc b/cheat/cheatsheets/wc new file mode 100644 index 0000000..c8d771e --- /dev/null +++ b/cheat/cheatsheets/wc @@ -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