What are your favorite command line aliases (bash/sh/tcsh) aliases? Here are a few of mine.

alias lsr='ls -lrt'
alias gon='cd $HOME/Notes'
alias devdb='mysql -h dev --user=x --password=secret dbname'
alias ec='rm *~'; # emacs cleanup
alias h='history'
alias eb='exec bash'; # Solaris sometimes defaults to sh
alias mr='more'
alias mroe='more'
alias qd='echo export DISPLAY=$DISPLAY'
alias ralias='. $HOME/.alias'; # reread aliases
alias ,,='cd ../..'
alias ..='cd ..'
alias c='clear'
  • 18
    Rather than passing your password in on the commandline to mysql (anyone else on the server could see it!), put the username and password in a ~/.my.cnf file, and simply specify -up. MySQL tools will pick those credentials up automatically, read mysql(1) for more info. – Alex J May 30 '09 at 4:54
  • +1 For alias ..='cd ..' – mosg May 13 '10 at 10:42
  • +1 for 'mroe'. I need to take care of my common misspellings... – gWaldo Nov 15 '10 at 15:06

52 Answers 52

function s()
    screen -t "$@" /usr/bin/ssh "$@"

Connect to a host in a new screen tab, with the device name as the tab title.

| improve this answer | |

My favourites that haven't been mentioned so far:

alias l='ls'
alias u='cd ..'
alias uu='cd ../..'
alias uuu='cd ../../..'
alias uuuu='cd ../../../..'

I'm not normally a fan of aliases that just shorten things, but I type ls so very much, and l only needs one hand.

| improve this answer | |
  • +1 - not a bad idea – Rook May 30 '09 at 7:48
  • 1
    ls (and cd) only needs one hand...if the keymap is Dvorak! Same hand as 'Enter', for that matter. – gbarry May 31 '09 at 1:56

none since I can never guarantee they'll be configured on EVERY system I'll log into (as myself, root, or whoever).

| improve this answer | |
  • 1
    Exactly! Harmless things like alias ls="ls --color=auto are fine, but changing the rm command etc.? Never. – user9474 Jun 14 '09 at 17:50

None, I change between systems so much every day that I basically gave up on it.

  • You don't sync your home directories between the various machines? xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion – Andy Lester May 31 '09 at 4:20
  • I maintain with a group of other administrators around 5k machines, most of these machines during their entire lifespan never had an remote interactive user session (all installation and configuration happens automatically), sometimes there is a wierd problem and you do have to log on. We have considered to have the user admins account to auto mount from a shared NFS partition, but for the use of it isn't worth it. – Martin P. Hellwig Jun 1 '09 at 9:16
  • 1
    ...don't have admin/root accounts include nfs directories in its path -- when NFS is bork, so is admin/root accounts. Some of my clients insist on learning this the hard way. – David Mackintosh Oct 22 '09 at 13:03
alias ..="cd .."
alias ...="cd ../.."

# mkdir and enter it immediately thereafter
mcd()           { mkdir $1 && cd $1; }

# when entering a directory, list the contents.
cd()            { builtin cd "$@" && ls; }
| improve this answer | |

The total contents of my "alias list" is:

I've spent enough time fixing unix machines I don't "normally" work with (one of the downsides of having been in-house unix admin for a software house, you end up on customer sites, A Lot) that the first thing I do is to "unalias -a", just so that any alias the normal production admin have don't happen to interact with a mis-spelling, after that it's too much hassle to customise.

This has carried over into my normal usage, too.

| improve this answer | |
alias rm 'mv -f \!* $WASTEBASKET'
alias unrm 'mv $WASTEBASKET/\!* .'

I know that many will disagree, but I like safety nets. (And please try to forgive me for using tcsh.)

This somewhat similar one should be outlawed, though:

alias rm 'rm -i'

I've seen people who were trained on systems with that alias, and then they type rm * on some other system, expecting to get questions about which files to delete, and then they sit there and watch it do exactly what it is supposed to do.


Some of the comments compared the move-to-wastebasket alias with the "-i" flag, saying that they are similar. But to me, there is an important difference. With "-i", you get the confirmation prompt every time you use the command, and it becomes something you expect and rely on. The wastebasket solution, on the other hand, works exactly like the standard rm, until you actually make a mistake and need to un-remove a file. It's a bit like the difference between training wheels and a spare tire in the trunk.

  • the bash equivalent requires a function: del() { path=readlink -f "$1" mkdir -p $WASTE$path mv $path $WASTE$path } Its not perfect (as it creates a new dir with the filename) but it works ok. (putting in newlines is left as exercise for reader!) – gbjbaanb Jun 1 '09 at 16:35
  • +1: I use Tcsh too :-) – anon Jun 2 '09 at 1:01
  • +1: you're forgiven for using tcsh ;) – bedwyr Jun 6 '09 at 1:20
  • 6
    Well in fairness, expecting a confirmation prompt and not getting one is just as bad as expecting it to go into a wastebasket and that not happening. There's no difference, really. – Dan Udey Jun 10 '09 at 1:49
  • @Dan: I thought the same. The alias really should not be called rm, but wb for wastebasket, or something similar. – user9474 Jun 14 '09 at 17:48

These are for zsh, but I imagine you could port them to another shell reasonably easily:

sudo() { [[ $1 == (vi|vim) ]] && shift && sudoedit "$@" || command sudo "$@"; } # sudo vi/vim => sudoedit
wst() { TZ=Australia/Perth date } # get local time no matter what server I'm on

FULLHOST=`hostname -f` 2>/dev/null || FULLHOST=`hostname` # reasonably portable, always gets a DHCP suffix too (if one exists)
SHORTHOST=`echo $FULLHOST | cut -d. -f1-2` # get the first two segments of hostname, which I used in my shell prompt
| improve this answer | |
  • Sorry for my ignorance, what is the difference between sudo vim and sudoedit? Is sudo edit = sudo $EDITOR ? – olle May 30 '09 at 16:22
  • sudoedit runs your editor under your account, rather than as root. That means you get access to your own ~/.vimrc and so on. – Alex J May 30 '09 at 17:00
  • 1
    +1 for changing sudo vi <somefile> to sudoedit <somefile! +more if I could – Kevin M Aug 4 '09 at 15:45

Here are some of my favorites. (A few are ZSH-specific.)

alias ls='ls -F --color=auto'
alias l='ls'
alias ll='ls -ahl'
alias ..='cd ..'
alias ...='cd ../..'
alias mv='mv -i'
alias mmv='noglob zmv -W'
alias mcp='mmv -C'

mkcd() {
        if [ $1 = "" ]; then
                echo "Usage: mkcd <dir>"
                mkdir -p $1
                cd $1

# ZSH global aliases for piping
alias -g H="| head"
alias -g T="| tail"
alias -g C="| wc -l"
alias -g L="| less"
alias -g G="| grep"
alias -g S="| sed -e"
alias -g A="| awk"

# Subversion related
alias ss='svn status'
alias sd='svn diff'
alias sc='svn commit'

# Git related
alias gs='git status'
alias gc='git commit'
alias ga='git add'
alias gd='git diff'
alias gb='git branch'
alias gl='git log'
alias gsb='git show-branch'
alias gco='git checkout'
alias gg='git grep'
alias gk='gitk --all'
alias gr='git rebase'
alias gri='git rebase --interactive'
alias gcp='git cherry-pick'
alias grm='git rm'

fortune -s  # Add to your profile to brighten your day :)
| improve this answer | |

For those troublesome colleagues:

alias ls=rm
| improve this answer | |
  • 2
    I prefer the much more subtle "alias vi=vi -R" – David Mackintosh Oct 22 '09 at 13:07

there are many aliases here wich are not neccessary:

alias c='clear'

can be replaced by just pressing [Ctrl]+[L]

alias mroe='more'

and similar: zsh provides spell correction by default, bash does it with extensions

alias something="history | grep $@"

pressing [Ctrl]+[R] does the same thing in bash/zsh

back='cd $OLDPWD'

the same can be done in every shell with

cd -
| improve this answer | |
jldugger@jldugger:~ $ alias 
alias ls='ls --color=auto'
alias youtube-dl='youtube-dl -t
| improve this answer | |
  • +1 for ls='ls --color=auto' – Matt Simmons May 30 '09 at 4:53
alias perg='grep -rni --exclude=\*.svn\*'
alias df='df -kTh'
alias ll="ls -l --group-directories-first"
| improve this answer | |
alias cdd='cd /wherever/my/current/project/is'
| improve this answer | |
alias ls="ls --color=auto -A -h -i -s --group-directories-first -l"
alias screen="screen -U"
alias sscreen="~/Projects/bin/start_screen.sh"
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | emacs'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
| improve this answer | |

p='ps auxww|grep -v grep|grep '

| improve this answer | |
  • In some cases, pgrep is useful. Not the same effect, but still useful. – Juliano Jun 8 '09 at 1:00

For searching old perl scripts for something:

alias searchperl 'find /place1 /place2 /place3 -name "*.pl" | xargs grep

Email myself a file:

alias mailthis 'mail -s mailthis email@email.com < '
| improve this answer | |
alias l='ls --color=auto -lsah'
alias ..='cd ..'

I miss it very often on other systems

| improve this answer | |
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort | uniq -c | sort -nr | head -10

Show the top 10 most used commands in your history.

| improve this answer | |
  • shorter version, no need for awk: history | cut -f 5 -d' ' | sort | uniq -c | sort -n | tail – Marcin Aug 1 '09 at 16:16
alias viewpw='aespipe -d < ~/.passwd.aes > ~/.passwd.dec && more ~/.passwd.dec && shred -u ~/.passwd.dec'

How I remember all my passwords...

| improve this answer | |

Here is my favorite, to find something in all of the Python code in the current and child directories, excluding those associated with subversion:

alias greppy="find . | grep -v [.]svn | grep [.]py$ | xargs grep "

| improve this answer | |

A few plucked from my bashrc:

alias grep='grep --color=auto'
alias egrep='grep -E --color=auto'
alias e='$EDITOR'
alias g='git'
alias csort='sort | uniq -c | sort -n' # column sort piped data
alias sl='ls' # fat fingers

Generally, I usually have my bashrc figure out what package manager the system uses and then have it aliased as apt and yum, meaning on any machine on which my bashrc runs, I can just do:

apt search foo
yum install foo
apt update

It's not perfect but most of the common actions are the same between yum and aptitude, by the time you're trying to do something more complicated you can just remember what OS you're on.

| improve this answer | |

Probably my favorite, since it makes writing new aliases so easy:

alias realias='vim ~/.bash_aliases;source ~/.bash_aliases'
| improve this answer | |

I would say this is my favorite alias.

alias resume='screen -D -R'

It proves to be very handy after my windows workstation is automatically rebooted every weekend (Firm's policy).

| improve this answer | |
if [ "$(uname)"="darwin" ]; then
  alias sleep_hdd='sudo pmset -a hibernatemode 1'
  alias sleep_ram='sudo pmset -a hibernatemode 0'
  alias sleep_combined='sudo pmset -a hibernatemode 3'
  alias cdproj='cd ~/Projects/Web'
  alias e='mate'
  alias vboxheadless='VBoxHeadless -startvm '
  alias subash='sudo bash'

if [ "$(uname)" = "SunOS" ]; then
  alias ls='ls -F'
  alias e='vim'
  alias subash='pfexec bash'
  • vboxheadless should already be in your $PATH: uname; which vboxheadless Darwin /usr/bin/vboxheadless – olle May 30 '09 at 16:27

This one works on most linux desktops:

alias go='xdg-open'

Opens a document or folder with the registered application, similar to the start command on windows.

  • 1
    Change it to xdg-open and it should work on any XDG-compliant desktop environment. – Juliano Jun 8 '09 at 0:59

A few more to add to the pile:

# little bit more readable PATH
alias path='echo -e ${PATH//:/\\n}'

# like others, I find these more efficient than
# typing cd ../../ etc
alias up='cd ..'
alias 2up='cd ../../'
alias 3up='cd ../../../'
alias 4up='cd ../../../../'

# found myself always mistyping this, so...
alias findy='find . -name'

alias targz='tar -xzvf'
alias hg='history | grep '
alias cls='clear'

# handy for the xclip tool
alias xclip='xclip -selection c'

# quick directory listing
alias ldir='ls -d */'

alias mys='mysql -uroot -psecret name-of-frequently-used-DB' 

alias trash='mv -t ~/.local/share/Trash/files --backup=t'
alias vb='vim ~/.bashrc'
alias +='pushd .'
alias _='popd'
| improve this answer | |
  • Storing passwords in scripts like this is potentially dangerous, unless you got it 600. Also upon execution your password goes to history file--also potentially dangerous. – Marcin Aug 1 '09 at 16:21
alias dsclean='find . -name .DS_Store -exec rm \{\} \;'
alias l='ls -lh'
alias ls='ls -G'

# Depends on your specific router
alias myip='curl -sn | grep td | tail -1 | tr -d '\''/<>a-z '\'''

# Start/stop local mysql installation
alias myserver='sudo /usr/local/mysql/support-files/mysql.server'
alias rssh='ssh -l root'
alias sc='./script/console'
alias sr='screen -r'
alias ss='./script/server'
alias sss='screen ./script/server'
alias up='svn up'
alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
| improve this answer | |

Do quick arithmetic from the command line. Use "x" for multiplication to avoid expansion.

function math
    echo "scale=2 ; $*" | sed -e "s:x:*:g" | sed -e "s:,::g" | bc

$ math 12,537.2 x 4
| improve this answer | |