Terminals Shouldn't Be Scary!

Terminals are crucial to mastering computers and are super fun to play with. But you don't need to be a gray beard to master the terminal! You can learn it bit by bit and have fun too. And this isn't some kind tongue-in-cheek expression. Try to remember the last thing your learned that made some drudgery less drudgeful (like finding out that adding site:blah.com in Google will limit results to just those from that site.) Wasn't that fun? This is the same kind of idea.

As a beginner, I wish I had a high level outline of terminal skills that I could then refer back to and incrementally improve over time, because I wanted to be able to spend a bit of time and gain a bit of skill immediately. Like a personal syllabus informed by practicing programmers that you follow every week. But really, incrementally making lists and personal notes is what I ended up doing and that worked very well. So actually, I'd recommend keeping a text file or Evernote note or something about your own terminal skills and simply updating it now and then. Bonus points if you edit that file in a terminal!

Terminal Crash Course is useful and has a lot of introductory material. It's a full course, though. Here's a shorter but much denser resource: Terminal Cheat Sheet.

Note: If you're on OS X, go ahead and install Homebrew. It allows you to install commands you don't already have access to. If you're on other operating systems, google for package manager [operating system] (if you squint, Google looks like a terminal too).

What should be in your list of things to remember? I'll compile my own list (tested only on OSX):

Things to Remember:

  • Use man a lot. man man.
  • Built in commands: man builtin
  • Search for commands even if you don't know the name: apropos (searches the short descriptions available in the whatis database on your system). Related: whatis
  • Know about piping inputs, redirection, and background jobs. Useful: nohup, bg, fg
  • Know your shell environment. Useful: env. If you use zsh along with oh-my-zsh, you have superpowers by default. Like auto-completing switches for commands or env variables or remote host names or using pushd/popd even when you cd around... Just chsh -s $(which zsh) to install, and then install oh-my-zsh.
  • Manage processes: top, ps (with -aux usually), kill
  • Manage disks: du, df
  • Check if commands exist: which [command]
  • Check the status of a file: stat [file]
  • Find things: mdfind or find, ag or ack, grep
  • Edit files: emacs (it's a Text Editor/Notepad, except you save things using Ctrl-X Ctrl-S, quit using Ctrl-X Ctrl-C, and use arrow keys and the enter key as normal; eg: emacs file.txt) or vim or [insert editor here]
  • Download things: wget or curl or restclient (github)
  • Access other computers: ssh, rsync, scp
  • Command multiple terminals: tmux or screen
  • Munge text: head, tail, sort, wc, cut, awk or ruby -ne (gets will grab a line for you in Ruby), sed. Or just write a Ruby script :)

Digging Deep:

I anticipate updating this post in the future, but I think I covered the basics. It's a hard thing to compress years of habit into one post, but thoroughly refreshing to do too. Hope it helps!


UPDATE:

  • While I listed man builtin, I should have called out attention to the ever useful type. type type tells you type is a shell builtin. You can use it to find out more about a semi-known or unknown shell invocation of any kind, like type some_alias (which prints out what some_alias is an alias of). Try it on files or environment variables or other commands! It's in the category of useful meta invocations like apropos or man or whatis.

  • Also, remember that for most commands, --help is invariably useful

  • Here's a resource with a good mix of beginner-accessibility, shortness of length, and denseness of content (except it's Linux focused and not OS X focused):


UPDATE 2 from 2015-10-20:

This is an amazing list of links about how to make good use of the command line on OS X machines.