Skip to content

Instantly share code, notes, and snippets.

@kirk86
Forked from mikedfunk/bash_cheatsheet.md
Created October 29, 2015 19:21
Show Gist options
  • Save kirk86/52d70bd218127774ab34 to your computer and use it in GitHub Desktop.
Save kirk86/52d70bd218127774ab34 to your computer and use it in GitHub Desktop.
cheatsheets

bash cheatsheet

some stuff I still need to memorize

c-a move to beginning of line
c-e move to end of line
c-k delete until end of line
c-w delete the previous word
c-r reverse-i-search (fuzzy search through command history)
grep -lir "my search string" * grep r: recursive, l: list files but not lines, search string, directory: \* is current, otherwise app/src/\* or whatever
history | grep my_search_string search through bash history
ls | grep my_search_string search through directory for file/folder names
cat my_file_name.txt | grep my_search_string search through file for text
ps -ax | grep my_process_name search through process list for a process like apache or mysql to see if it's running. then kill 123 or whatever the process id is
cat my/path/to/file.txt
vim !$
Load the last arguments with the current command. Bang, cash!
mkdir -p a/b/c/ make the entire path a/b/c/ even if a or b don't exist yet.
top shows the most expensive programs at the top. %cpu, %memory, time
yum search sdffsdlkjf search for packages with sdffsdlkjf in the name
scp myfile myshortcut:~/ copy a file in the current dir called myfile to the ssh configured connection into homedir/.
reboot reboot the server... usually requires root
dmesg Special log before console was available. Shows log of startup procedures.
ps aux | awk -F ',' '{print $1}' pipe ps aux result to awk, which will split based on whatever you put after -F (default is space, leave off -F for space) and the third part print the delimited part.
ps aux | awk '{ if ($1 == "mfunk") {print $2} }'g pipe ps aux to awk, which searches a space delimited split of each line for the first item being 'mfunk'. print the second delimited element.
cat myfile1.txt myfile2.txt > mynewfile.txt concatenate two files to a new file
watch ...
find ...
sed ...
df -H display free disk space. -H is human readable format in base 10.
tar -zcvf destinationfile.txt.tar.gz fromfile.txt compress file with .tar.gz
tar -zxvf compressed_file.txt.tar.gz decompress file with .tar.gz (or .tar.bz2, or .tgz)

git cheatsheet

some stuff I still need to memorize

git prune origin deletes all remote tracking branches for non-existent remote branches
git clean -f deletes .orig backup files
git reset --soft HEAD~12 && git commit squash the last 12 commits
git latest show all branches sorted by last updated (.gitconfig alias added by me)

SERVER: boson (Need sudo) SCRIPTS LOCATION: /data1/scripts/<SITE NAME> BRANCH FOR TESTING:

STEP 1 - push code to STG

*** never PUSH (commits) to master / only PULL from master ***

  1. *** ask dev if they've pulled from master ***
  • if not yet then ask them to pull from master and resolve all conflicts
  • if yes then
  1. push to staging - sudo ./1_push.sh
  2. double check with dev the list of commits
  3. click 'q' to continue - if there are no new commits then this is not required
  4. verify branch name with timestamp ex. testwithchinh-10-05-15-07-51 Ready for Activation on staging
  5. On staging the folder that you uploaded will be activated immediately. No need to run 2_push.sh to activate folders on staging.

*** COMMITS SINCE LAST PRODUCTION PUSH (ie commits NOT in origin/master): --- if no commit messages below this line then this indicates there are not changes

PUSH TO PROD:

Is it Friday?? Remember NO PROD PUSHES on FRIDAYS!

STEP 1 - push code to PROD

  1. Create JIRA release ticket
  2. *** Have you pulled from master recently??!!??*** *** never PUSH to master / only PULL from master ***
  3. sudo ./1_push.sh PROD
  4. CONFIRM DIFF OF YOUR CODE step with Dev *** IMPORTANT ***
    • click 'q' to exit out commit diff prompt
    • if there is a long list of commits you may use space or arrow down to scroll to the end
    • Use nodiff if you do not want to review changes. $./1_push.sh <branch_name> PROD nodiff
  5. click y to continue when confirmed

STEP 2 - activate code on PROD

  1. sudo ./2_activate.sh PROD
  2. confirm folder ready for activation with menu time ** typically the first one **
  3. select number
  4. enter 'YeS' to confirm merging of dev branch into master HOW TO REVERT
  5. sudo ./2_activate.sh PROD
  6. select which version to revert to ** typically 1 is the most recent behind LIVE **
  7. ** make sure dev team is aware of the revert ** - meaning dev will need to pull from master once bug is fixed

ICE UPDATES

-- if there is an ice update then talk to austen

How to get info on diff and commit logs for QA:

1.Connect to boson (10.100.1.3) 2. cd /data1/local_git_checkouts/git..com/ 3. git fetch origin updates origin 4. git checkout 5. git status confirm that you are on VERY IMPORTANT STEP BEFORE PULL IN NEW CODE 6. git pull origin updates with the latest version of from origin 7. (OPTIONAL). To check if the dev has synced their dev branch with master do the following: git pull origin master If you see: Already up-to-date. Then developer has updated the branch with latest master changes. If you see files being pulled down or any conflict messages. Alert the developer that they need to pull master into their branch and then do the following: git reset --hard Make sure developer pulls master into their branch before continuing testing. (OPTIONAL END) 7. git log origin/master.. Shows commit log in single line format, does not show changed files 8. git lgn origin/master.. Shows commit log including list of changed files 9. git diff origin/master.. Shows diff – Very useful to confirm changes by dev

mongo cheatsheet

some stuff I still need to memorize

db.dbname.insert({color: 'red'}) Insert document
db.dbname.update({color: 'red'}, {color: 'blue'}, true) Upsert document (if no document found, create one)
db.dbname.update({color: 'red'}, {color: 'blue'}, false, true) Upsert multiple documents
db.dbname.update({color: 'red'}, {$set: {height: 6.2}}) Update document. $set uses sql behavior to leave unspecified fields alone.
db.dbname.update({color: 'red'}, {$inc: {height: 2}}) Update. $inc increments or decrements by the specified value.
db.dbname.remove({color: 'red'}) Delete
db.dbname.find({color: 'red'}) Find all documents where color is red
db.dbname.find({color: 'red', $or: [{color: 'green'}]}) Find all documents where color is red or green
db.dbname.find({color: {$exists: true}}) Find all documents where color is a column
db.dbname.find({weight: {$gt: 50, $lte: 20}}) Find all documents where weight is greater than 50 and less than or equal to 20
db.dbname.find({name: /^Snoo/}) or db.dbname.find({name: {$regex: /^Snoo/}}) Find all documents where name starts with Snoo

my .tmux.conf additions

prefix esc vim copy mode. v to start selection, move around with usual vim keys. y to copy. p to paste anywhere in tmux.
prefix Y send tmux clipboard to mac clipboard
prefix c-j, c-k, c-h, c-l move pane divider up/down/left/right by 10 lines at a time.
prefix j, k, h, l switch to pane above, below, to the left, to the right. consistent with vim bindings.
mux create Dork create a tmuxinator session called Dork and open the config.
mux Dork spin up a Dork tmuxinator session

my .vimrc.local additions

c-w c-j, c-w c-k, etc. move the vim window by 10 lines. assumes top or left window for direction.
c-a c-j, c-a c-k, etc. move the tmux pane by 10 lines.
leader rp prompt for vimux command
leader rl run last vmux command
leader rx exit vmux window
leader ri inspect vmux window
c-n :tabnew
leader bpw go to breakpoint window
leader bpt toggle breakpoint on current line
leader dp cd to project root
:S /my_var search for my_var, MY_VAR, myVar, and MyVar.
:%S/my_var/my_new_var/g replace my_var, MY_VAR, myVar, and MyVar with my_new_var in it's respective format
crs or cr_ coerce to snake_case
crm coerce to MixedCase
crc coerce to camelCase
cr- coerce to dash-separation
leader bt open all buffers in tabs
leader te open the current buffer in a new tab
leader pt open ptag window
leader pcl close ptag window
leader pcf php-cs-fixer on this file
leader pcw php-cs-fixer on this directory
leader pd phpdocumentor on the current function
/ c-r 0 paste buffer 0 into the search field
g/ visually select the last search result
leader c-] open a tag in a new tab
:Ag "my search" search recursively on current pwd, load results in quicklist, ]q and [q to jump to results

mysql cheatsheet

some stuff I still need to memorize

Tab completion works for table names and field names. Use it in selects and describes.

mysql -u root einstein2 login as root with no password, use the einstein2 database
desc(ribe) table_name; show the columns for table_name
mysqldump -h myhostname.com -u myusername -p mypassword mydbname > mydumpname.sql starting on the local machine, get a dump from a remote machine and deposit it locally.
mysql -h myhostname.com -u myusername -p mypassword mydbname < mydumpname.sql Import from dump into db
(from mysql prompt with db used) source mydumpname.sql Import from dump into db

#spf-13 cheatsheet

Easy Windows (c-k, c-j, c-h, c-l) Maximize the window in the given direction
Easy motion (,,w ,,W ,,b ,,B) Show easy motion shortcuts in the direction indicated by the motion
Fast Tabs (s-h, s-l) switch tabs left or right
,f0 - ,f9 set fold level
cwd change working directory to that of the current file
w!! save when you forgot to sudo
,ew :e %%
,es :sp %%
,ev :vsp %%
,et :tabe %%
,= equal size windows (c-w =)
,ff show all lines with keyword under cursor, ask which to jump to
zl, zh Easier horizontal scrolling (zL, zH)
c-d, c-u (in autocomplete popup) page down, page up
,ac toggle AutoCloseTag mappings to work with xhtml and xml
c-e open/close nerdtree, mirror nerdtree location with other tabs
,nt or ,e Find the current file in nerdtree
,a= run tabularize on the = sign. Also works with & : :: , |, > (for =>)
,sl session list
,jt set filetype to json
,tt open tagbar
,sl session list
,gs :Gstatus
,gd :Gdiff
,gc :Gcommit
,gb :Gblame
,gl :Glog
,gp :Gpush
,gw :Gwrite
,gg :GitGitterToggle
c-y close neocomplcache popup and complete word
c-e close neocomplcache popup and *don't* complete word
c-n next neocomplcache result
c-p previous neocomplcache result
c-d next page of neocomplcache results
c-u previous page of neocomplcache results
,u undotree toggle
,/ toggle highlight search (hlsearch)
,P preview markdown in browser

tmux cheatsheet

some stuff I still need to memorize

c-a c-o rotate panes
option click-drag select text in a box, native mac style. the usual cmd-c copies.
tmux attach -t Work attach to the Work session
tmux new-session -S Work create a new Work session
ctrl-l clear scrollback (like cmd-k for vanilla terminal)

vim cheatsheet

some stuff I still need to memorize

* (forward) # (backward) search for word under cursor
g* search for word under cursor, but match "rainbow" when you search for "rain"
gd will take you to the local declaration (e.g. of a variable)
c-w, c-] open a split of the tag beneath the cursor ( } instead for preview window)
c-w, c-z close the split window (:pc to close preview window)
c-o (insert mode) enter an arbitrary vim command, then return to insert mode
5gt go to tab #5 (numbered from first tab)
c-o jump backwards ("out")
c-i jump forwards ("in")
L jump to bottom of screen ("low")
M jump to middle of screen ("middle")
H jump to top of screen ("high")
zt put this line at the 't'op of the screen
zb put this line at the 'b'ottom of the screen
zz put this line at the middle of the screen
vi) select in ()
[} go to previous { (top of method or construct)
(in insert mode) c-r 0 paste text from register 0 (default register)
(in insert mode) c-w delete the previous word
(in insert mode) c-u delete to the beginning of a line
(in visual mode) o move cursor to the opposite side of the selection
:cw display the clist (quickfix list / location list) in a split. ]l and [l to go to next and prev item.
:args *.php
:tab all
opens all php files in the current dir in tabs (replaces current tabs). ** for recursive.
ctrl-w g] list matching tags, enter a number to open that tag in a window
ctrl-w T (capital) open the current window a in a new tab. Useful with the previous command.
:tabm [n] Move the current tab to the n position. If n is omitted it will move to the last position. If it's 0 it will move to the first.
:set ft=html set the file type to html. useful for views.
d/search_term delete until the search_term.
]m [m ]M [M go to the start of the next method, previous, end of next method, previous.
zj, zk next fold, previous fold
:noh or :nohl Clear the current highlight. The following search will still be highlighted.
}, { Move to the next/previous vertical whitespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment