Wednesday, September 01, 2010

Command line tips for OS X and Linux

I wrote last year about keeping .ssh, .gpg, and other sensitive information on an encrypted disk and create soft links so when the disk is mounted, sensitive information is available.

I have a few command line tricks that save me a lot of time that are worth sharing:
  • Use a pattern like history | grep rsync to quickly find recent commands. Much better than wading through your history.
  • Make aliases for accessing services on specific servers for example alias kb2_mongo='mongo xxx.xxx.xxx.xxx:11222'. By having consistent naming aliases for your servers and for running specific services like the mongo console, it is easy to both remember your aliases and use them.
  • Create aliases with consistent naming conventions to ssh to all of your servers. I use different prefixes for my servers and for each of my customers.
  • Create an alias like alias lh='ls -lth | head' to quickly see just the most recently modified files in a directory, most recent first.
  • For your working development system create two letter aliases to get to common working directories (most recent projects, writing, top level code experiment directory, etc.). I try to be consistent and use some of the same aliases on my servers.

3 comments:

Alex Ott said...

Ctrl-R allows to interactively search in history (bash/zsh)

Mark Watson, author and consultant said...

Thanks Alex, much faster than my grep approach. It is still sometimes nice to see all matches at once with grep, but your is definitely the better approach.

-Mark

Alex Ott said...

You can also press Ctrl-R during search, to move to next matching record (Ctrl-s should also work to search to previous matching record) - this is standard readline (emacs) key bindings