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
mana 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 thewhatisdatabase 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 usezshalong with oh-my-zsh, you have superpowers by default. Like auto-completing switches for commands or env variables or remote host names or usingpushd/popdeven when youcdaround… Justchsh -s $(which zsh)to install, and then install oh-my-zsh. - Manage processes:
top,ps(with-auxusually),kill - Manage disks:
du,df - Check if commands exist:
which [command] - Check the status of a file:
stat [file] - Find things:
mdfindorfind,agorack,grep - Edit files:
emacs(it’s a Text Editor/Notepad, except you save things usingCtrl-X Ctrl-S, quit usingCtrl-X Ctrl-C, and use arrow keys and the enter key as normal; eg:emacs file.txt) orvimor [insert editor here] - Download things:
wgetorcurlorrestclient( github) - Access other computers:
ssh,rsync,scp - Command multiple terminals:
tmuxorscreen - Munge text:
head,tail,sort,wc,cut,awkorruby -ne(getswill grab a line for you in Ruby),sed. Or just write a Ruby script :)
Digging Deep:
- Snooping around (
amazing post about dtrace scripts and basic tools):
dtrace,dtruss,iotop,iftop,iosnoop,execsnoop,opensnoop - Profiling programs:
sample,dtracescripts (it has a language likeawk’s), language specific tools - Experiment!
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 usefultype.type typetells youtype is a shell builtin. You can use it to find out more about a semi-known or unknown shell invocation of any kind, liketype some_alias(which prints out whatsome_aliasis an alias of). Try it on files or environment variables or other commands! It’s in the category of useful meta invocations likeaproposormanorwhatis. -
Also, remember that for most commands,
--helpis 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.