Skip to content

Instantly share code, notes, and snippets.

@ninetails
Last active February 8, 2016 01:47
Show Gist options
  • Save ninetails/6874764 to your computer and use it in GitHub Desktop.
Save ninetails/6874764 to your computer and use it in GitHub Desktop.
my personal cheat sheet

Making this for my personal use.

For Markdown Syntax Cheat Sheet, access here. And for Github Flavored, here.

Linux

For a complete one, access here.

Table of Contents

  1. Linux Command Line
  2. Images
  3. Screen
  4. Node
## Linux (command line)
cat {filename}

replace content of a file

echo '{content}' > {filename}

append content to a file

echo '{content}' >> {filename}

replace in file

sed -i 's/{from}/{to}/g' {filename}

less with colors (raw input)

less -r

show directories on current folder

ls -d */

show directory tree

tree -d -C -I "[0-9]*"

* only directories, colored, excluding numeric one. require to install tree.

watch + ls (with columns) with colors

watch --color "ls -C --color"

less + ls (with columns) with colors

ls -C --color | less -r

folder size

du -hs /folder/path/

list directories recursively

find . -type d

list files *.ext recursively without "./"

find . -iname '*.ext' -printf '%P\n'

watch for 15 seconds files created in 2 minutes

watch -n 15 find . -cmin -2

list all files inside folder

tree -if ${PWD}

find string in files

grep "string" ./*.ext

find string in files recursive

grep -r "string" .

open grep in text editor

grep -l "string" . | xargs subl

copy terminal output to clipboard

echo "a" | xclip -selection clipboard

* require to install xclip.

tar.7z

compress

tar cf - {directory} | 7za a -si {directory}.tar.7z

uncompress

7za x -so {directory}.tar.7z | tar xf

Encoding

See encoding

file -i {file}

With iconv

iconv -f l1 -t utf8 -o {filename.new} {filename}

* require iconv installed. New filename must not have same name as filename.

With recode

recode l1..u8 *.csv

* require recode installed. Can do batch change of encoding.

### Images
for f in *.png; do convert "$f" "${f/%png/jpg}"; done

* require Imagemagick installed.

Optimize jpeg files

jpegoptim [files]

* require jpegoptim installed.

### Screen
screen -S {sessionname}

list all sessions

screen -list

or

screen -ls

detach screen

Command: ^A, d
### Node

source: http://stackoverflow.com/questions/352098/how-can-i-pretty-print-json

print json on Console

node -e "console.log(JSON.stringify(JSON.parse(process.argv[1]), null, '\t'));" '{"foo":"lorem","bar":"ipsum"}'

pretty print json file

node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(process.argv[1])), null, 4));" filename.json

pretty print jsonp file

node -e "global[process.argv[2]] = function (a) {console.log(JSON.stringify(a, null, 4));};require(process.argv[1]);" './filename.js' 'callback'

Screen

Table of Contents

  1. Commands
## Commands
screen -S <session_name>

List sessions

screen -list

screen -ls

Reattach to a running session

screen -x

Reattach to named session

screen -x <session_name>

Ultimate attach

screen -dRR

Internal commands

Always preceeded with Ctrl+a:

  • ? Help
  • * Window list
  • c Create new window
  • 0 Open window 0
  • S Split horizontal
  • | Split vertical
  • A Rename region
  • tab Switch focus between splitted regions
  • X Close current region
  • Q Close all regions except current one
  • d Dettach current session

Copied from here

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
Ctrl+⇧+↩ insert line before
Ctrl+⇧+↑ move line (or selection) up
Ctrl+L select line (repeat to select next lines)
Ctrl+D select word (repeat select others occurrences in context for multiple editing)
Ctrl+M jump to closing bracket for current code, repeat to jump to opening bracket
Ctrl+⇧+M select all contents of the current brackets (curly brackets, square brackets, parentheses)
Ctrl+KK delete from cursor to end of line
Ctrl+K+⌫ delete from cursor to start of line
Ctrl+] indent current line(s)
Ctrl+[ un-indent current line(s)
Ctrl+⇧+D duplicate line(s)
Ctrl+J join line below to the end of the current line
Ctrl+ / comment/un-comment current line
Ctrl+⇧+/ block comment current selection
Ctrl+Y redo, or repeat last keyboard shortcut command
Ctrl+⇧+V paste and indent correctly
Ctrl+Space select next auto-complete suggestion
Ctrl+U soft undo (somehow undoes your movements; it jumps to your last change before undoing it when you repeat this command)

Navigation/Goto Anywhere

Ctrl+P quick-open files by name in your project (doesn’t seem to need an actual project set up, it just searches in the directories around the currently-opened file
Ctrl+R goto symbol (functions and classes) in the file. Same as Ctrl+P, then type @
Ctrl+; goto word in current file. Same as Ctrl+P, then type #
Ctrl+G goto line in current file. Same as Ctrl+P, then type :

General

Ctrl+⇧+P command prompt
Ctrl+KB toggle side bar

Find/Replace

Ctrl+F find
Ctrl+H replace
Ctrl+⇧+F find in files

Tabs

Ctrl+⇧+t open last closed tab (just like in your browser)
Ctrl+PgDn cycle down through open tabs, cycle up with Ctrl+PgUp
Ctrl+⇆ cycle through last tabs (repeat to go back further in history)

Split window

Alt+⇧+2 split into two columns
Alt+⇧+1 revert to single column
Alt+⇧+5 grid (4 groups)
Ctrl+[1,2,3,4] jump to “group” (pane)
Ctrl+⇧+[1,2,3,4] move file to specified group

Bookmarks

Ctrl+F2 toggle bookmark
F2 next bookmark
⇧+F2 previous bookmark
Ctrl+⇧+F2 clear bookmarks

Text manipulation

Ctrl+KU upper case
Ctrl+KL lower case

ViM

Usage

Basic Usage

  • :q - Exit
  • :q! - Exit force
  • :w - Write
  • :wq or ZZ - Write & Quit
  • h j k l - Navigation (Visual Editor)

Plugins

Open or create a New File:

vim index.html

New HTML5 file ("_" is the cursor position):

html:5_

Then <c-y>,.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment