Skip to content

Instantly share code, notes, and snippets.

# change directory
cd # back to the last one you were in
mkdir dir && cd !$ # cd into the director you just created
take dir # cd into the director you just created - a custom function
# Movement on the command line
ctrl + a # move to the beginning of command
ctrl + e # move to the end of the command
ctrl + w # delete one word to the left
ctrl + k # delete all to the right
esc + f # move cursor forward
esc + b # move cursor back
# Common Grep pattern. Recursively searches directory, case insensitive, show
# line numbers, show the 5 lines before and after
grep -irn -C 5 [pattern] [location]
@btoone
btoone / export-snippets-to-files.rb
Created April 3, 2012 03:54
Imports a plist and exports content to files
require 'plist'
require 'active_support/inflector'
# require 'gist'
# include Inflector
r = Plist::parse_xml('snippet-export.plist')
r.each do |r|
filename = "#{r['language'].parameterize}-#{r['id']}.txt"
# Use git archive command to export a git repo
git archive master | tar -x -C /someplace/else/
# show last modified date for each git branch in a project
for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";done|sort -r
# global search and replace
find test/ -type f | xargs sed -i .old -e "s/test/example/g"
# display control/non-printable characters
sed -n 'l' input.txt
# backup a file before changing it by adding a suffix
# check mail log for error and warnings
egrep '(warning|error|fatal|panic):' /var/log/maillog | less
# Create an iso from a mac
hdiutil makehybrid -iso -o Microsoft-Office-2011.iso /Volumes/Microsoft\ Office\ 2011/
# Using a list with the mv command
mv README.{txt,textile}
mv config{,.old}
mv foo{,bar}
mv {,~}foo
mv {~,}foo