After a few introductory guides, improving your command line fu just comes down to seeing what other developers use. Here are some less common tools I’ve found invaluable enough to use on every system.
For reference, I keep my dotfiles on Github.
.inputrc
Readline (the GNU library for reading user input that Bash and others use) has it’s own dotfile: ~/.inputrc
. A sample of the life changers (mostly just saner defaults) in my own inputrc:
Search history with Up/Down arrow keys.
"\e[A": history-search-backward
"\e[B": history-search-forward
By default, Bash steps through your entire history when using the arrow keys. With this setting, you only step through commands that start with what you’ve already typed. E.g. if you’ve typed git
and then hit up, it only steps through commands starting with git
, like git status
, git add .
. This is basically a more convenient Ctrl-R
for recursive history search.
Ignore case for tab completion
set completion-ignore-case on
Example: ~/docum <Tab>
will autofill ~/Documents/
Show all suggestions after pressing tab once instead of twice
set show-all-if-ambiguous on
Example: ~/d <Tab>
immediately shows the list of possible completions (~/Desktop
, ~/Documents
), rather than waiting for you to mash tab twice like a buffoon.
SSH Escape Sequences: ~.
<ENTER>~.
kills an SSH session. Comes in handy when you wake up your computer to find an unresponsive SSH session. (Enter is not required, but typically I find I need it). You can see more escape sequences with <ENTER>~?
.
Syntax highlighted less and cat
You can use pygments
to give less
syntax highlighting when viewing files:
# In my .bashrc
export LESSOPEN="|<path/to/lesspipe.sh> %s"
alias less='less -R'
Where <path/to/lesspipe.sh>
points to this script..
Also just running pygmentize
works as a colorized cat
.
OSX: pbpaste and pbcopy
On OSX, pbpaste
and pbcopy
(which I have aliased to pp
and pc
) give you access to the clipboad, making it incredibly convenient to run commands to modify the contents of your clipboard like pp | tr -s ' ' | pc
.
Other small things
Beyond that, the smaller things add up:
alias la="ls -alh"
is the first command I mistakenly assume on any new system: long listedls
with all files and human readable sizestr
,cut
,grep
, andxargs
are most of the commands I use. For example:
# Get running processes |
# filter by search |
# remove extra spaces |
# select column with pid |
# pass to kill
ps aux | \
grep -i 'my-process' | \
tr -s ' ' | \
cut -d ' ' -f 2 | \
xargs kill
python -m json.tool
: pretty print json. For example:
> echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool
{
"bar": "ipsum",
"foo": "lorem"
}
sorted-du
: find what’s taking space:
sorted-du () {
paste -d '#' <(du -cs *) <(du -chs *) | sort -rn | cut -d '#' -f 2
}
uniq -c
to count occurrences. Sinceuniq
only works on adjacent lines, you generally sort:
> history | tr -s ' ' | cut -d' ' -f3 | sort | uniq -c | sort -rn
1195 la
988 cd
542 make
536 todo
...
-
watch to refresh a command and watch it change (not on OSX by default).
-
explainshell.com for when you’re too lazy to search man pages for multiple arguments