Here are some of the top command line posts from Today I Learned.
My goal with this series is to pause and highlight some of the top posts from the first year of Today I Learned. Today we'll look at Command Line, our fourth-most active channel.
At Hashrocket, our developers pair every day using Vim and Tmux, sometimes remotely, so command-line proficiency is a must. The Dotmatrix is one of several projects we maintain to maximize our terminal environment.
Here are the top five most liked command line posts, in order, from the first year of Today I Learned.
If you've been using Homebrew on your Mac (if you have a Mac you really should) you may not be aware that every time you upgrade your brew formulas using
brew update && brew upgrade Homebrew is leaving behind a copy of the old versions.
With package updates becoming available daily you may end up with gigabytes of space being wasted away on old package versions.
To see how much space the old versions are using run
brew cleanup -n. When I ran that command I got:
==> This operation would free approximately 9.2G of disk space.
If you feel like reclaiming that diskspace just run the command again without the
Enjoy space! 🚀
You can use
!$ as a way to reference the last argument in the last
command. This makes for an easy shortcut when you want to switch out
commands for the same long file name. For instance, if you just ran
a file to see its contents
$ cat /Users/jbranchaud/.ssh/config
and now you want to edit that file. You can just pass
!$ to the
$ vim !$
Hit enter or tab to get the full command:
$ vim /Users/jbranchaud/.ssh/config
h/t Dorian Karter
If you've created an unnamed tmux session or you no longer like the original name, you can open a prompt to change it by hitting
Replace the existing name with the desired name and hit enter.
h/t Dorian Karter
To edit a command in bash you often need to jump around in the line and revert to using the arrow keys. As a vim/emacs user this becomes a bit of a clumsy non-ergonomic movement, here are some shortcuts to help you keep your fingers on the home row. If you are an emacs user these are going to look familiar.
ctrl-p- previous command entered
ctrl-n- next command entered
ctrl-a- jump to BOL
ctrl-e- jump to EOL
alt-b- jump word forward
alt-f- jump word backwards
alt-b- jump character forward
alt-f- jump character backwards
If these shortcuts don't work try running
set -o emacs
Alternatively you can turn on vi mode in your shell by calling
set -o vi, which you can add to your
.zshrc or add
set editing-mode vi to your
.inputrc. After setting this you can enter normal mode by hitting escape and use vi motions to edit/move.
Your shell just got upgraded. 💪💻
If you are adding customizations to your zshrc, such as adding auto completion for a certain gem, you want to make sure that the gem is installed before performing any action.
gem list [gemname] -i command returns a boolean representing whether a gem is installed or not.
if `gem list lunchy -i`; then echo "Lunchy gem is installed!"; # do some configuration here fi
If you wish to be more granular you can check whether a specific version is installed by adding the
--version [version] flag.
if `gem list lunchy -i --version 0.10.4`; then echo "Lunchy v0.10.4 is installed!"; # do some configuration here fi
Today I Learned had a spike in traffic near the beginning of the year, and these posts are mostly from that time. But there's a lot of great Command Line tips from earlier. See them all here:
Keep refining those commands, and learning every day.