matyuschenko
11/26/2015 - 9:56 AM

Terminal tricks & recipes

Terminal tricks & recipes

sed 's/snow/rain/' forests.txt
# sed stands for "stream editor"
# It accepts standard input and modifies it based on an expression,
# before displaying it as output data.

# above:
  # s: stands for "substitution".
  # snow: the search string, the text to find.
  # rain: the replacement string, the text to add in place.
open -a TextEdit filename
# The -a flag specifies any application you want, so it's applicable to any number of situations, including ones where TextEdit isn't the default editor.
# -t opens in the default editor (i.e. if you use BBEdit, TextMate, etc.)
# -e will open the file specifically in TextEdit
# Ctrl+A, Ctrl+E - go to beginnning or end of the line
# Alt+B, Alt+F - move cursor one word left or right
# Ctrl+K, Ctrl+U - del everything right or left from cursor

# Drag folder/file to terminal window to insert its path

# nice list of commands from Codecademy

history | grep ssh # find command in history
!455 # execute command #455
^nanp^nano # rerun previous command with typo
<command>!$ #get args from previous command
alias new_alias="<command>" # alias; run in terminal to make temp alias
!cat # run previous cat command
!cat:p # echo previous cat command
!! # equals last command, e.g. sudo !!

grep -iRl Mount geography/mountains
# i for case-insentive "global regular expression print"
# R for resursive: search all files in a directory
# l outputs filenames only (by default also prints lines containing matched)

history | grep ssh # find command in history
env | grep $PATH # find variable in env

for i in test.txt test2.txt; \
  do cat ${i} | head -n 20; \
done