Ask HN: Share your favourite bash/zsh aliases
I'll start by adding the most essential.
alias o="open"
alias x="exit"
alias g="git"
alias gs='git status'
alias gd='git diff'
alias g-='git checkout -'
alias serve='python -m SimpleHTTPServer 8000'
alias mem='top -l1 | grep PhysMem'
74 comments
[ 35.2 ms ] story [ 325 ms ] threadThe incredible amount of time this has saved over the years is great, but the real benefit never having remember either inspect archive files for the initial directory or remember to do this dance:
https://gist.github.com/Fannon/41b0a6104435943cd826
Without atool you have to either 1) create a temporary dir youself and do the dance I showed above, or 2) always inspect every archive before you decompress it to see if it has multiple top-level files, or 3) accept that typing "tar xvf" or similar will sometimes spam your current directory (often $HOME) with thousands of files.
Similar to how git tends to remove mental blocks around branching (you not longer have ot worry about the cost of making an arbitrary change), atool frees you from having to worry about how an archive was created. This has, in practice, saved huge amount of time and mental effort.
I stopped using oh-my-zsh because of these. There is a popular program called 'gap' which got over-written by one of these aliases.
One problem I had with gulp. I had dir name gulp and zsh got confused weather to go to the dir or execute the cmd.
alias diskspace="du -S | sort -n -r |less"
alias pyserver='python -m SimpleHTTPServer'
alias phpserver='php -S localhost:8000'
alias phplog='tail -f /var/log/apache2/error.log'
[1]: https://github.com/ndbroadbent/scm_breeze
prompts when you overwrite something using cp ("oops, wrong folder")
alias rm='rm -I'
prompts when you delete more than three files ("oops, a space too much in rm ./ *")
First, alias this on Linux to get the 'open' command to work like OSX (e.g. 'open file.pdf'). It shadows a real 'open' command, but I have never used it, so no big loss :
The second one I use all the time. A process that is stuck on I/O (or other uninterruptible syscalls), or even a Python interpreter stuck in a C extension, won't always respond well to Ctrl-C. However, Ctrl-Z (suspend) and this alias (kills the last suspended process group) do work relatively well : This one I use a lot for copying the output of a command to the clipboard. Just run 'command | pbcopy' and then Ctrl-V elsewhere. pbcopy is actually an OSX command, I aliased it on Linux for ease of use : This one runs a program under GDB. You can run e.g. 'gdbrun =python test.py' and debug C extensions more easily:For example, YADR is pretty good ( https://github.com/skwp/dotfiles ).
Of the ones not listed already in this thread, a few standards that are great to have:
L - less
H - | head
T - | tail
G - | grep
C - | wc -l
N - /dev/null
S - | sort
_ - sudo
alias cpcd="echo -ne \$(pwd) | pbcopy"
Useful when you have a file picker in front of you, but you know you have a terminal already in the directory you want. Switch to the term, cpcd, switch to the file picker, Go to folder (⌘-Shift-G), Paste (⌘-V).
when you have a terminal open in a directory, but another app has a file picker box.
I find the oh-my-zsh git plugin's default aliases to be unintuitive and hard to remember. Simply not having to type 'git ' before everything is good enough for me.
shopt -s autocd