Using the Terminal like it’s 2017

Pieces of the Command Line

For the uninitiated, it’s easiest to think of it in three pieces. The easiest things to experiment with are changes with your terminal, followed by change to your shell, followed by trying new utilities.

  1. Shell: this is the main app a terminal runs. It defines everything from what directory you’re in to what the prompt looks like. Bash and Zsh are the two most common these days, but there’s plenty of others.
  2. Utilities: these are a set of command-line applications that are ubiquitous, mostly thanks to POSIX, BSD, and GNU. For example, ls, tar, zip, and grep are all actually separate apps that are just ported and installed most everywhere.

Terminals

First, make sure you’re using a modern terminal. For OS X, this probably means switching to iTerm2. For linux, it means basically anything besides xterm and rxvt. Windows is still behind, but I’d recommend either the confusingly named Git Bash or the equally confusingly named Bash on Ubuntu for Windows.

  • Get a nice theme. Terminals support color themes. Most terminals support true color these days too. Solarized and base16 are good places to start.
  • Use tabs in terminals. Tab support in browsers was huge because it kept things more organized and manageable; tabs in terminals do the same thing.
  • Use the keyboard to paste. Most terminals use ctrl-shift-v on windows and linux (cmd-v on macs) to paste. Use that instead of right-click or middle-click. I want to take away the mouse every time I watch someone use their mouse to paste.
  • Increase scrollback. Most terminals default to only 500–1000 lines history displayed that you can ‘scroll back’ and see. You’re never going to regret setting this to 10000 or higher. Some terminals even support infinite scrollback now if you turn it on.

Shells

Most everything defaults to using a shell called bash; even Windows and OS X. These recommendations focus on bash, but there’s equivalents for other shells. I recommend sticking with bash until you know everything in this article before considering switching.

  • Change your prompt. It’s easy to do. For Bash, it’s the PS1 variable; for Zsh, it’s just PROMPT. For bash, bash-git-prompt is a pretty good option if you want to just try something.
  • Configure bash. There’s features in bash that are great and just not turned on by default. Use Bash’s shopt builtin to turn on features like cdspell, dirspell, and autocd. The first two will let bash auto-correct simple typos. The third means you can omit typing “cd “ to change directories. I also recommend dotglob, extglob, globstar, and histappend.
  • Add timestamps to your bash history. If you set HISTTIMEFORMAT in your .bashrc, then bash will track and display when commands are run in your command history. While you’re doing that, set HISTSIZE and HISTFILESIZE to 10000 to get 10,000 lines of history instead of the typical 500.
  • Use control-r to search through your history instead of history | grep. If you want something even better, install and use fzf.
  • Use alt-., !!, and !100 to use previous commands instead of retyping or copy-pasting. For example, alt-. copies the last argument of the previous command onto the command prompt as if you had retyped it.

Utilities

  • Use color output when available. For example, ls --color or ls -G on OS X. Turn on color output if it isn’t already in git, npm, and gulp too.
  • Use vim not vi. Typing in vi usually still runs vim, it just runs it in a very minimal, limited fashion that’s lacking decades of improvements.
  • Use modern equivalents of old CLI apps, like htop instead of top. mawk or gawk instead of awk. bzip2 (or tar cvjf) instead of gzip (tar cvzf.) dig instead of nslookup. less +F instead of tail -f. less instead of more.
  • Use aliases. Make bash aliases for commands you run the most, and git aliases for git commands.
  • Configure SSH. Create a ~/.ssh/config file and set a default username. Use Host sections to configure usernames and ports for other systems you often use. If you want to do even more, turn on persistent SSH connections.
  • tig let’s you browser through git history. Enable color and unicode characters to make it look even better.
  • ack-grep, ag, and ripgrep are all newer alternatives to grep that are nearly always faster than stock grep is.

Remember

Remember that programmers have been using these things for 30–40 years. They’ve been improving and using them for nearly everything imaginable for 30–40 years. No matter what problem you run into, someone else found it and figured out a solution before you.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin Hamer

Kevin Hamer

45 Followers

The Principal Engineer at Imarc, Erratic Author on Medium. Writing about web development and being a better web developer.