DEV Community

Discussion on: Getting Started With the Terminal

Collapse
 
wulymammoth profile image
David • Edited

Nice write-up! A few things I'd like to share that seem to go amiss when introducing someone and even experienced programmers to the terminal and a shell...

  1. how to get help without defaulting to Google all the time -- built-in Unix utilities like all the ones that you've listed usually have options. The easiest way to know what's available is to resort to the manual aka (man pages) that can simply be invoked with $ man <some util>, (e.g. $ man ls). It is very useful to use ls -l (long format) and ls -la (long with directories)

  2. man pages typically adopt vi movements, but without diving into that, they can simply be searched by first hitting the / (forward slash) followed by some keyword or option (e.g. /foobar) will search for foobar in the man pages

  3. using slash will take you directly to the first match, we can use n (lowercase) to go to the "next" instance and <shift>-n (capital) to go back

  4. most of the time when we make a new directory, we'd also like to change into it after, but we can do it in a single command: $ mkdir foo && cd $_. The last command is captured in the _ (underscore) var and to access variables, we use the $ prefix

  5. if we're moving back and forth between two directories, we can also use - to go back and forth instead of trying to remember or pushing up/down to find the command that took us into that directory:

$ pwd 
/Users/me/Desktop

$ cd foo
foo $

foo $ pwd
/Users/me/Desktop/foo

foo $ cd -
/Users/me/Desktop
  1. readline commands - allow you to navigate within line and edit. This is a huge efficiency gain. See: readline.kablamo.org/emacs.html (it's the first result that came up, so disregard the emacs in the URL). Surprisingly most of our tools are built with readline, so these typically work in any place that allows you to type text (i.e. Chrome, Apple Notes, Google Doc, etc) so they are worth learning even outside of a shell

  2. previous/next commands (stop using the up/down arrow) - if you're a touch-typer that does not like to remove your hands away from the "home row", this one's for you! <shift>-p (mnemonic for "previous") is the same as the up-arrow and if you scrolled past it, then <shift>-n (mnemonic for "next") is the same as the down-arrow. But what's even better? reverse-i-search activated with <ctrl>-r followed by keyword(s) and it will find the first command that matches what you type. You may hit <ctrl>-r repeatedly to go to the next previous match and to move forward, <ctrl>-s

Collapse
 
dailydevtips1 profile image
Chris Bongers

Yes! Very nice additions indeed, will look into incorporating some of these for sure!