Skip to content

Instantly share code, notes, and snippets.

@revolunet
Last active May 22, 2022 22:51
Show Gist options
  • Save revolunet/1beba10d8dc938e70376 to your computer and use it in GitHub Desktop.
Save revolunet/1beba10d8dc938e70376 to your computer and use it in GitHub Desktop.
bash productivity

Shell edition

  • Ctrl + a – go to the start of the command line
  • Ctrl + e – go to the end of the command line
  • Ctrl + k – delete from cursor to the end of the command line
  • Ctrl + u – delete from cursor to the start of the command line
  • Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
  • Alt + b – move backward one word (or go to start of word the cursor is currently on)
  • Alt + f – move forward one word (or go to end of word the cursor is currently on)
  • Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
  • Ctrl + r – search the history backwards
  • Ctrl + g – escape from history searching m

Shell commands

  • !! – run last command
  • !$ – the last word of the previous command (same as Alt + .)
  • !$:p – print out the word that !$ would substitute
  • !* – the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘)
  • !*:p – print out what !* would substitute

Snippets

# find and copy/rename 
find ./xxx -iname 'some.json' -exec sh -c 'cp "{}" other-path/"$(basename "$(dirname "{}")")"/some.json' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment