diff --git a/README.md b/README.md index 0d5f3d7..0b677a7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,28 @@ Cheat Sheets ============ +> **NOTE**: This repo is best used by placing a bookmark in your address bar. + +This is a collection of cheat sheets that I have compiled over the years that I +put together while learning various tools. They contain some good information +and a few gems that I have learned along the way. Feel free to contribute. + +## Contents + +- [Bash] +- [Git] +- [GnuPG] +- [irssi] +- [JIRA] +- [mutt] +- [nmap] +- [openssl] +- [tmux] +- [uml] +- [vim] +- [zsh] +- [other] + ## License https://github.com/JoshuaEstes/CheatSheets/blob/master/ See [LICENSE] for full license. + +[Bash]: https://github.com/JoshuaEstes/CheatSheets/blob/master/bash.md +[Git]: https://github.com/JoshuaEstes/CheatSheets/blob/master/git.md +[GnuPG]: https://github.com/JoshuaEstes/CheatSheets/blob/master/gnupg.md +[irssi]: https://github.com/JoshuaEstes/CheatSheets/blob/master/irssi.md +[JIRA]: https://github.com/JoshuaEstes/CheatSheets/blob/master/jira.md +[mutt]: https://github.com/JoshuaEstes/CheatSheets/blob/master/mutt.md +[nmap]: https://github.com/JoshuaEstes/CheatSheets/blob/master/nmap.md +[openssl]: https://github.com/JoshuaEstes/CheatSheets/blob/master/openssl.md +[tmux]: https://github.com/JoshuaEstes/CheatSheets/blob/master/tmux.md +[uml]: https://github.com/JoshuaEstes/CheatSheets/blob/master/uml.md +[vim]: https://github.com/JoshuaEstes/CheatSheets/blob/master/vim.md +[zsh]: https://github.com/JoshuaEstes/CheatSheets/blob/master/zsh.md +[other]: https://github.com/JoshuaEstes/CheatSheets/blob/master/other.md [LICENSE]: https://github.com/JoshuaEstes/CheatSheets/blob/master/LICENSE diff --git a/bash.md b/bash.md index e69de29..3144e29 100644 --- a/bash.md +++ b/bash.md @@ -0,0 +1,75 @@ +Bash Cheat Sheet +================ + +## Moving + +| command | description | +|----------|--------------------------------| +| ctrl + a | Goto BEGINNING of command line | +| ctrl + e | Goto END of command line | +| ctrl + b | move back one character | +| ctrl + f | move forward one character | +| alt + f | move cursor FORWARD one word | +| alt + b | move cursor BACK one word | + +## Other + +| command | description | +|----------|--------------------------------| +| ctrl + d | Delete the character under the cursor | +| ctrl + l | Clear the screen (same as clear command) | +| ctrl + p | Fetch the previous command from the history list, moving back in the list (same as up arrow) | +| ctrl + n | Fetch the next command from the history list, moving forward in the list (same as down arrow) | +| ctrl + u | Clear all BEFORE cursor | +| ctrl + k | Clear all AFTER cursor | +| ctrl + r | Search backward starting at the current line and moving 'up' through the history as necessary | +| crtl + s | Search forward starting at the current line and moving 'down' through the history as necessary | +| ctrl + c | kill whatever is running | +| ctrl + d | Exit shell (same as exit command) | +| ctrl + w | delete the word BEFORE the cursor | +| ctrl + t | swap the last two characters before the cursor | +| ctrl + y | paste (if you used a previous command to delete) | +| ctrl + z | Place current process in background | +| ctrl + _ | undo | +| esc + t | Swap last two words before the cursor | +| esc + . | | +| esc + _ | | +| alt + [Backspace] | delete PREVIOUS word | +| alt + < | Move to the first line in the history | +| alt + > | Move to the end of the input history, i.e., the line currently being entered | +| alt + ? | | +| alt + * | | +| alt + . | print the LAST ARGUMENT (ie "vim file1.txt file2.txt" will yield "file2.txt") | +| alt + c | | +| alt + d | | +| alt + l | | +| alt + n | | +| alt + p | | +| alt + r | | +| alt + t | | +| alt + u | | +| ~[TAB][TAB] | List all users | +| $[TAB][TAB] | List all system variables | +| @[TAB][TAB] | List all entries in your /etc/hosts file | +| [TAB] | Auto complete | +| !! | Run PREVIOUS command (ie `sudo !!`) | +| !vi | Run PREVIOUS command that BEGINS with vi | +| cd - | change to PREVIOUS working directory | + +# Kill a job + +n = job number, to list jobs, run `jobs` + +```bash +kill %n +``` + +Example: + +```bash +kill %1 +``` + +## References + +1. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html diff --git a/git.md b/git.md index e69de29..955db5e 100644 --- a/git.md +++ b/git.md @@ -0,0 +1,141 @@ +Git Cheat Sheet +=============== + +## Subtree Example + +### Add sub-project as remote + +```bash +git remote add -f RemoteName RemoteUrl +``` + +### Run `git subtree` command + +```bash +git subtree add --prefix Path/To/Put/Code NameOfRemote master --squash +``` + +#### Pull subtree as needed + +```bash +git fetch NameOfRemote master +git subtree pull --prefix Path/To/Put/Code NameOfRemote master --squash +``` + +### Reference + +* http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree + +## Create a branch without a parent + +Very useful when you are updating a project that you are rewriting. For example, +say you are using semantic versioning and are wanting to start a new major +version. + +```bash +git checkout --orphan BRANCH +``` + +## Delete All Branches that have been merged + +Great for cleaning up local branches that aren't being used any more. + +```bash +git checkout master +git branch --merged | grep -v "\*" | xargs -n 1 git branch -d +``` + +## Ignore changes to a file that is being tracked + +### Ignore + +```bash +git update-index --assume-unchanged [directory|file] +``` + +### Unignore + +```bash +git update-index --no-assume-unchanged [directory|file] +``` + +## How to ignore dirty submodules + +Edit your ``.git/config`` and add ``ignore = dirty``. + +```text +[submodule "path/to/submodule"] + path = path/to/submodule + url = git://github.com/username/repo.git + ignore = dirty +``` + +## Clone a repo and give name other than origin + +```bash +git clone -o upstream https://repo.git +``` + +## Ignore Files for Repository without using `.gitignore` + +Add the file `.git/info/exclude` and fill it with the contents you want to ignore. This will ONLY apply to the +repository and will not be tracked by git. + +## Squash Commits + +```bash +git log +``` + +Count the number of commits that you have made, let's say the previous 5 are your commits. + +```bash +git rebase -i HEAD~5 +``` + +The first commit leave as `pick` the rest will need to be changed to `squash`. After that you will be able to +leave a new commit message or just leave as is to keep the commit messages from all previous commits. + +## Search for a specific line of code/file in the history + +```bash +git log -S[search term] +``` + +Example: + +```bash +git log -SThatOneFile.php +``` + +## Copy file from one branch to current branch + +Copy a file from `branch` and put into staging. + +```bash +git checkout BRANCH path/to/file.ext + +# Real Life Examples +git checkout origin/featureBranch web/js/random.js +# Pulls into your current branch web/js/random.js from +# origin/featureBranch +``` + +## Git Grepping for fun and profit! + +```shell +# Basic grep (case sensitive) +$ git grep 'search term' + +# Case Insensitive search +$ git grep -i 'search term' + +# Search within a directory +$ git grep 'search term' src/ + +# Search only files with `php` extension +$ git grep 'search term' -- '*.php' + +# Grep in the 'src/` directory, only yml files +$ git grep 'search term' -- 'src/**.yml' +``` diff --git a/gnupg.md b/gnupg.md index e69de29..0b740ca 100644 --- a/gnupg.md +++ b/gnupg.md @@ -0,0 +1,64 @@ +GnuPG Cheat Sheet +================= + +## Listing Key Pairs + +```bash +gpg --list-keys +``` + +For listing keys with the fingerprint, run + +```bash +gpg --fingerprint +``` + +## Generate New Key Pair + +```bash +gpg --gen-key +``` + +## Encrypt a message on command line + +```bash +echo "Put message here" | gpg --armor --encrypt --recipient Joshua > FILE.gpg +``` + +This will put the encrypted text into `FILE.gpg` which you can send to someone or keep for +later use. For decrypting the message, see the next section. + +## Decrypt a message from the command line + +```bash +cat FILE.gpg | gpg +``` + +Displays the decrypted text on the command line. + +## Only display user X's key information + +```bash +gpg --fingerprint Joshua +``` + +## Signing Messages + +```bash +echo "This is a top secret message" | gpg --clearsign +``` + +## Signing Text Files + +```bash +gpg --clearsign example.txt +``` + +This will create `example.txt.asc` file. + +## Verify Signatures + +```bash +gpg --verifiy example.txt.asc +``` + diff --git a/irssi.md b/irssi.md index e69de29..d59a218 100644 --- a/irssi.md +++ b/irssi.md @@ -0,0 +1,11 @@ +Irssi Cheat Sheet +================= + +M = Meta Key, meta key is either the left alt or esc key. + +| command | description | +|----------|-------------| +| M + p | Scroll up in window +| M + n | Scroll down in window +| ctrl + p | Previous window +| ctrl + n | Next window diff --git a/jira.md b/jira.md index e69de29..2c957f2 100644 --- a/jira.md +++ b/jira.md @@ -0,0 +1,8 @@ +Jira Cheat Sheet +================ + +## Find by Mentions of current user within the past 7 days + +```sql +comment ~ currentUser() AND updatedDate >= -7d +``` diff --git a/mutt.md b/mutt.md index e69de29..b27270f 100644 --- a/mutt.md +++ b/mutt.md @@ -0,0 +1,226 @@ +Mutt Cheat Sheet +================ + +## General + +These key bindings will work on almost any menu you are in. + +| command | description | +|------------|-------------| +| * | Move to last entry +| = | Move to first entry +| : | Enter muttrc command +| > | Scroll down one line +| < | Scroll up one line +| [ | Scroll up half a page +| ] | Scroll down half a page +| ? | Help +| ; | Apply next function to tagged messages only +| ! | Invoke command in subshell +| return | Select the current entry +| esc + / | Search up +| / | Search down +| H | Move to top of page +| j | Move to next entry +| k | Move to previous entry +| ctrl + l | Redraw screen +| L | Move to bottom of page +| M | Move to middle of page +| n | Move to next match of search +| q | Exit menu +| t | Tag current entry +| z | Move to next page +| Z | Move to previous page + +## Index Menu + +When you first open mutt you are in the index menu. + +| command | description | +|---------------|-------------| +| & | Link tagged message to current one +| # | Break the thread in two +| % | Toggle whether mailbox will be rewritten +| . | List mailboxes with new mail +| $ | Save changes to mailbox +| @ | Display full address of sender +| | | Pipe message to a shell command +| esc + tab | Jump to previous new or unread message +| return | Display message +| tab | Jump to next new or unread message +| a | Create alias from message sender +| b | Remail message to another user +| esc + c | Open a different folder (Read Only) +| c | Open a different folder +| esc + C | Make text/plain copy +| C | Copy message to another file/mailbox +| esc + d | Delete all messages in subthread +| d | Delete current message +| ctrl + D | Delete all messages in thread +| D | Delete messages matching a pattern +| esc + e | Use the current message as a template for a new one +| e | Edit the raw message +| ctrl + E | Edit attachment content type +| f | Forward message with comments +| ctrl + F | Wipe passphrase from memory +| F | Toggle the important flag for message +| g | Reply to all +| G | Retrive mail from POP server +| h | Display message and toggle header weeding +| j | Move to next undeleted message +| esc + k | Mail a PGP key +| k | Move to previous undeleted message +| ctrl + K | Extract supported public keys +| esc + l | Show current limit pattern +| l | Only show messages matching a pattern +| L | Reply to specific mailing list +| m | Compose new message +| esc + n | Jump to next subthread +| ctrl + N | Jump to next thread +| N | Toggle new flag +| o | Sort messages +| O | Sort messages in reverse order +| Q | Query external program for addresses +| q | Save changes to mailbox and quit +| r | Reply to message +| ctrl + P | Jump to previous thread +| esc + p | Jump to previous subthread +| p | Print current message +| esc + P | Check for classic PGP +| P | Jump to parent message in thread +| ctrl + R | Mark current thread as read +| R | Recall a postponed message +| esc + r | Mark current subthread as read +| esc + s | Save text/plain copy and delete +| s | Save message/attachment to mailbox/file +| esc + t | Tag current thread +| ctrl + T | Untag messages matching a pattern +| T | Tag messages matching pattern +| esc + u | Undelete all messages in subthread +| u | Undelete current entry +| ctrl + U | Undelete all messages in thread +| U | Undelete messages matching pattern +| esc + v | Collapse/uncollapse current thread +| v | Show mime attachments +| esc + V | Collapse/uncollapse all threads +| V | Show mutt version number and date +| w | Set a status flag +| W | Clear status flags from message + +## Pager Menu + +| command | description | +|---------|-------------| +| # | | +| a | | +| b | | +| c | | +| esc + c | | +| C | | +| esc + C | | +| d | | +| ctrl + D | | +| esc + d | | +| w | | +| W | | +| e | | +| ctrl + E | | +| f | | +| F | | +| g | | +| h | | +| j | | +| J | | +| k | | +| K | | +| & | | +| L | | +| ctrl + L | | +| m | | +| n | | +| N | | +| ctrl + N | | +| esc + n | | +| o | | +| O | | +| p | | +| ctrl + P | | +| esc + p | | +| Q | | +| q | | +| r | | +| R | | +| ctrl + R | | +| esc + r | | +| esc + e | | +| s | | +| S | | +| esc + s | | +| t | | +| T | | +| u | | +| esc + u | | +| ctrl + U | | +| v | | +| V | | +| \\ | | +| @ | | +| | | | +| ? | | +| space | | +| - | | +| ^ | | +| $ | | +| ! | | +| : | | +| . | | +| / | | +| esc + / | | +| return | | +| P | | +| esc + P | | +| esc + k | | +| ctrl + K | | +| ctrl + F | | + +## Useful key remaps + +These need to be placed in your `muttrc` file. I use vim and so I want to use some of the +same commands to manage my mail. + +```muttrc +# Does not replace and currently mapped keys and acts like the vim command gg and takes +# you to the top of the page +bind index gg first-entry + +# Replaces the retrieval of mail from a POP server. This will take you to the bottom of +# the page, just like it does in vim +bind index G last-entry +``` + +## Flags + +When viewing messages in the index menu, you will see various flags such as `N` which mean +the messages is new and `D` which means that the message is to be deleted. This is a short +list of those flags. + +| flag | description | +|------|-------------| +| ! | Message is flagged +| * | Message is tagged +| + | Message is To: you and only you +| C | Message is Cc: to you +| d | Message has attachments marked for deletion +| D | Marked for deletion +| F | Message is From: you +| K | Contains PGP key +| L | Message is sent to a subscribed mailing list +| n | Thread contains new messages (Only when thread is collapsed) +| N | Message is new +| o | Thread contains old messages (Only when thread is collapsed) +| O | Message is old +| P | Message is PGP encrypted +| r | Message has been replied to +| s | Message is signed +| S | Message is signed and verified +| T | Message is to you and has others in To: or Cc: diff --git a/nmap.md b/nmap.md index e69de29..2035224 100644 --- a/nmap.md +++ b/nmap.md @@ -0,0 +1,8 @@ +Nmap Cheat Sheet +================ + +## Scan a Port + +```bash +nmap -p 80 google.com +``` diff --git a/openssl.md b/openssl.md index e69de29..02a8d92 100644 --- a/openssl.md +++ b/openssl.md @@ -0,0 +1,8 @@ +OpenSSL Cheat Sheet +=================== + +## Generate Self-Signed Certificate and Private Key + +```bash +openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt +``` diff --git a/other.md b/other.md index e69de29..f70fc1c 100644 --- a/other.md +++ b/other.md @@ -0,0 +1,13 @@ +Other Cheat Sheets +================== + +## Using `less` instead of tail + +```shell +less +F -R /path/to/logfile.log +``` + +* To scroll up and down, press `+c` +* Return to tail mode, press `F` + +The `+F` says to follow? The `-R` will process any ANSII color codes. diff --git a/tmux.md b/tmux.md index e69de29..4c2d056 100644 --- a/tmux.md +++ b/tmux.md @@ -0,0 +1,93 @@ +Tmux Cheat Sheet +================ + +`ctrl + b` is default to enter before you enter the commands. `M` = Left Alt key +or ESC key + +## Windows + +| command | description | +|---------|-------------| +| c | Create a new window. +| & | Kill the current window. +| n | Change to the next window. +| p | Change to the previous window. +| , | Rename the current window. +| l | Move to the previously selected window. +| w | Choose the current window interactively. +| M-n | Move to the next window with a bell or activity marker. +| M-p | Move to the previous window with a bell or activity marker. + +## Panes + +| command | description | +|---------|------------ | +| " | Split the current pane into two, top and bottom. +| % | Split the current pane into two, left and right. +| x | Kill the current pane. +| ; | Move to the previously active pane. +| o | Select the next pane in the current window. +| ! | Break the current pane out of the window. +| q | Briefly display pane indexes. + +## Other + +| command | description | +|---------|-------------| +| d | Detach the current client. +| $ | Rename the current session. +| [ | Enter copy mode to copy text or view the history. +| f | Prompt to search for text in open windows. +| r | Force redraw of the attached client. +| L | Switch the attached client back to the last session. +| $ | Rename Current Session +| : | Enter the tmux command prompt +| ? | List all key bindings +| f | Search window titles and goto that window +| i | Briefly display window information +| r | Force redraw of the attached client. +| s | Select a new session for the attached client interactively. +| t | Show the time. +| = | Choose which buffer to paste interactively from a list. +| ] | Paste the most recently copied buffer of text. + +## Create a new session + +Any of these will work. + +```bash +tmux +tmux new +tmux new-session +``` + +## Reattach to a session + +Any of these commands will work. + +```bash +tmux at +tmux attach +tmux attach-session +``` + +## List sessions + +Any of these commands will work. + +```bash +tmux ls +tmux list-sessions +``` + +## How to copy and paste + +1. Enter copy-mode `C-b [` +2. Move to text, press `Space` to select text, move cursor to highlight text +3. Press `Enter` +4. Back at the command prompt, press `C-b ]` and the text you selected is pasted + +## References + +* http://www.openbsd.org/cgi-bin/man.cgi?query=tmux&sektion=1#KEY+BINDINGS + diff --git a/uml.md b/uml.md index e69de29..d8ab0d3 100644 --- a/uml.md +++ b/uml.md @@ -0,0 +1,50 @@ +UML Cheat Sheet +=============== + + +``` +<> +<> +<> + +- private +# protected ++ public + +name : type = default value +``` + +Examples: + +``` +<> +Name\Space\To\ClassAbstract +--- +- $privateAttribute : string = '' +# $protected : integer = 1 ++ $public : string = 'DefaultValue' +--- ++ getPrivateAttribute() : string ++ getValueForKey($key : string) : mixed ++ get($key : string, $default : mixed = null) : mixed +``` + +``` +Class A "uses" Class B +[Class A]- - - ->[Class B] +``` + +``` +Class A "has a" Class B +[Class A]---->[Class B] +``` + +``` +Company "owns" Employee +[Company]⃟----[Employee] +``` + +``` +Ford "is a" Car +[Car]◁----[Ford] +``` diff --git a/vim.md b/vim.md index e69de29..235d71e 100644 --- a/vim.md +++ b/vim.md @@ -0,0 +1,159 @@ +Vim Cheat Sheet +=============== + +## Open a file + +| command | description | +|---------------------|-------------| +| vim + file.ext | Open file at last line +| vim +42 file.ext | Open file at line 42 +| vim +/^include_path | Open the file at the line that starts with include_path + +## Exiting + +| command | description | +|---------|-------------| +| :q | Quit +| :wq | Write and Quit +| :q! | Quit without saving +| ZZ | Write and quit +| ZQ | Quit without saving + +## Moving + +| command | description | +|-----------------|-------------| +| b | Move to the BEGINNING of the word +| e | Move to the END of the word +| ge | Move to the END of the PREVIOUS word +| gg | Move to START of buffer +| G | Move to END of buffer +| h | Move cursor LEFT +| j | Move cursor DOWN +| k | Move cursor UP +| l | Move cursor RIGHT +| *n* gg OR *n* G | Move to n line (n represents a digit) +| w | Move to the start of the next word +| ctrl+b | Move BACK one page +| ctrl+f | Move FORWARD one page + +## Inserting Text + +| command | description | +|---------|-------------| +| a | append after the cursor +| A | append at end of line +| i | Insert before cursor +| I | Insert before line +| o | Create new line below and start editing +| O | Create new line above and start editing +| gi | Place cursor where you were last editing (Useful for when you exit Insert mode and then need to go back where you once were) + +## Other Commands + +| command | description | +|----------|-------------| +| u | undo +| ctrl + R | redo + +## Buffers + +| command | description | +|---------|-------------| +| :ls | List current buffers +| :bn | Next buffer +| :bp | Previous Buffer +| :bd | Close Buffer + +## Tabs + +| command | description | +|---------|-------------| +| :tabnew | create new tab +| :tabn | move to NEXT tab +| :tabp | move to PREVIOUS tab +| :tabfir | goto FIRST tab +| :tablas | goto LAST tab + +## Windows + +| command | description | +|------------|-------------| +| ctrl + w s | Split window horizontally +| ctrl + w v | Split window vertically +| ctrl + w q | Close current window, if last window then exit vim +| ctrl + w c | Close current window, will not exit vim +| ctrl + w o | Make window the only window on the screen + +## Spell Checking + +```vimrc +" ~/.vimrc +" Enable spell checking +set spell +``` + +### Commands + +| command | description | +|---------|-------------| +| ]s | Move to next misspelled word +| [s | Move to previous misspelled word +| z= | Show list of possible replacements words + +## Marcos + +1. Press `q` then press another key that you want to assign it to. Example: `qq` +1. Enter commands +1. Press `q` when finished +1. To run the macro, press `@` and then the key that it is assigned to. Example `@q` +1. NOTE: Can be ran multiple times. Enter the number of times you want it to run then the macro. Example `10@q` will run the macro 10 times. + +## Code Folding + +| command | description | +|---------|-------------| +| zo | OPEN code fold under cursor +| zc | CLOSE code fold under cursor +| zR | OPEN ALL code folds +| zM | CLOSE ALL code folds + +## Marks + +| command | description | +|-------------|---------------------------| +| ma | Create mark **a** in file | +| 'a | Jump to mark **a** | +| d'a | Delete line mark **a** | +| :marks | List marks | +| :delmarks a | Deletes mark **a** | +| :delmarks! | Deletes all marks | + +## Auto complete + +| command | description | +|-------------------|-------------| +| ctrl + x ctrl + o | Autocomplete current word +| ctrl + x ctrl + n | word completion next +| ctrl + x ctrl + p | word completion previous +| ctrl + x ctrl + f | Complete filename +| ctrl + x ctrl + l | Whole line completion + +### Enable + +```vimrc +" ~/.vimrc +autocmd FileType python set omnifunc=pythoncomplete#Complete +autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS +autocmd FileType html set omnifunc=htmlcomplete#CompleteTags +autocmd FileType css set omnifunc=csscomplete#CompleteCSS +autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags +autocmd FileType php set omnifunc=phpcomplete#CompletePHP +autocmd FileType c set omnifunc=ccomplete#Complete +``` + +## Multi Liners + + :set tw=80 Sets text width to 80 characters + gg Goto first line + gqG Format file till you reach the last line diff --git a/zsh.md b/zsh.md index e69de29..0a236f8 100644 --- a/zsh.md +++ b/zsh.md @@ -0,0 +1,4 @@ +Zsh Cheat Sheet +=============== + +Still haven't got around to digging in a reading the man pages for this yet.