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'
(
73 comments
| 38 points
| on HN
)
shopt -s autocd
The 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.
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:#e.g. mktouch ~/Desktop/test/file.md would make the test dir if it didn't exist then touch file.md inside of it
mktouch() {
Common GUI programs I often launch from the command line I put an alias in my .bashrc for. e.g.
Use magit in emacs as a git front-end instead of dozens of git aliases. You can continue to use vi or eclipse or whatever for editing. Use dired in emacs to replace a lot of file manipulation aliases.
Replace all your complicated aliases with ^r reverse search. For example, instead of typing
I type because 'check' is the most distinct string in that command in my mind, and by 'che' bash has already located the last time I typed it in the history. Save lots of history: Which directory is hiding all the bytes? Machines on the local network: Set the permissions to allow sharing of files in a directory between users in the same group (probably doesn't work on bsd/osx):ali <name of alias> <command>
to get it put this in your .bashrc
When I realize I type a command often, I just push the up arrow to get the command again, append "ali" infront of it and turn it to an alias. Works direclty.And of course the alias to show the list of all aliases:
That only lists what's in .bash_aliases, along with any comments.
Why not just run alias without arguments? It lists all active aliases, however and whenever they were defined.
"Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output."alias _=sudo
alias aria='aria2c --file-allocation=none -c -x 10'
alias aria_list='aria2c --file-allocation=none --force-sequential=true -c -x 10 -i'
alias d='dirs -v | head -10'
alias hdmi='xrandr --output HDMI1 --auto --right-of LVDS1'
alias history='fc -l 1'
alias la='ls -lAh'
alias lock='i3lock -c #1E90FF'
alias ls='ls --color=tty'
alias md='mkdir -p'
alias pyfind='find . -name ".py"'
alias pygrep='grep --include=".py"'
alias rd=rmdir
alias reload_sound='pulseaudio -k && sudo alsa force-reload' # when sound messes up
alias settings=gnome-control-center
alias sl=ls
alias utorrent='utserver -settingspath /opt/utorrent-server-alpha-v3_3/ &'
alias vga='xrandr --output VGA1 --auto --right-of LVDS1'
alias vga_same='xrandr --output VGA1 --auto --same-as LVDS1'
[1]: https://github.com/ndbroadbent/scm_breeze
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 ffs=sudo
example usage:
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.
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.
https://github.com/uberspot/dotfiles/blob/master/.alias
https://github.com/colindean/getip
I've not actually used it as a script in a while, and it appears to be broken in that regard at the moment (something about ld not being able to write to the tmp directory). However, its Makefile is still operational. Maybe someone will see this and submit a PR that fixes it?
alias ff="find . -iname"
alias size="du -h --max-depth=1"
alias latest="ls -lt |head"
alias orly='sudo $(history -p \!\!)'
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'
Shows up all the things I still need to work on in a given project (assuming of course that you annotate your code...).
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.
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 ./ *")
https://github.com/fish-shell/fish-shell
alias serv="ssh [email protected]"
alias work="cd /Users/myname/Sources/mycompany/myproject"
sed -i "$ a\#custom shortcuts \nx(){ case \$1 in .tar.bz2) tar xjf \$1;; .tar.gz) tar xzf \$1;; .bz2) bunzip2 \$1;; .rar) rar x \$1;; .gz) gunzip \$1;; .tar) tar xf \$1;; .tbz2) tar xjf \$1;; .tgz) tar xzf \$1;; .zip) unzip \$1;; .Z) uncompress \$1;; esac; } \nf(){ grep -R -I \"\$1\" ./*; } \np(){ ps aux | grep \$1 | grep -v grep; } \nown(){ sudo chmod 777 -R \${1:-.} && sudo chown -R \${USER} \${1:-.}; } \nalias u='sudo apt-get update && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y' \nalias l='ls -la' \nalias ..='cd ..' \nalias i='sudo apt-get install -y ' \nalias gg='git add . && git commit -a -m "." && git push -u -f origin master'" ~/.bashrc && source ~/.bashrc
More here https://github.com/gulakov/nodejs-starter/blob/master/README...