Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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'
share|improve this question

closed as off topic by sysadmin1138 Jul 10 '11 at 23:39

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

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 Jurkiewicz May 30 '09 at 4:54

52 Answers 52

jldugger@jldugger:~ $ alias 
alias ls='ls --color=auto'
alias youtube-dl='youtube-dl -t
share|improve this answer
alias perg='grep -rni --exclude=\*.svn\*'
alias df='df -kTh'
alias ll="ls -l --group-directories-first"
share|improve this answer
For the first one try "ack". it is a programmer's grep ;) –  hayalci May 31 '09 at 0:47
alias cdd='cd /wherever/my/current/project/is'
share|improve this answer

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
share|improve this answer
+1 for changing sudo vi <somefile> to sudoedit <somefile! +more if I could –  Kevin M Aug 4 '09 at 15:45
alias ls="ls --color=auto -A -h -i -s --group-directories-first -l"
alias screen="screen -U"
alias sscreen="~/Projects/bin/"
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'
share|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.

share|improve this answer
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
#. Darwin:
.  : source
ls : ls -G -F
resize : osascript << EOF
  tell app "Terminal"
    set number of rows of first window to 25
    set number of columns of first window to 80
    set custom title of first window to "${PROFILE}"
  end tell

#. Linux:
.  : source
ls : ls --color=auto -F -X -h general - I don't like using aliases too much though, you become dependent and learn to use something which only ever exists if you yourself make it so. I'd then feel handicapped when jumping on someone else's machine, even for a minute - so my general advice would be to use aliases very lightly.

For example aliasing ls to ls -F is ok, because it only has cosmetic effects, but aliasing to it ls -l or something - I would never do. I don't like these ll for ls -l aliases either for the same reason.

share|improve this answer

We tend to use rdp a bit, because we can only access certain servcices via windows so I like:

alias rdt='rdesktop -d UOFA -g 1024x768 -u '

usage is

rdt <win_username> <winhost>

A lot of our stuff is in LDAP so search as the directory manager is useful (with an apporpirately configured /etc/openldap/ldap.conf):

alias dmsearch='ldapsearch -x -LLL -D"<directory_admin_bind_dn>" -W '

alias budate='date +%Y%m%d-%H%M' E.g. cp -p some-conf.comf someconf-'budate'.conf NB repalce the single quotes with backticks. Serverfault wont let me put in backtick literals and I cant work out how to escape backticks.

alias psg='ps aux|grep '

share|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.

share|improve this answer
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
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'
share|improve this answer
function s()
    screen -t "$@" /usr/bin/ssh "$@"

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

share|improve this answer
alias l='ls --color=auto -lsah'
alias ..='cd ..'

I miss it very often on other systems

share|improve this answer

Not an alias but a function, since i hate manually checking of the sshd is up after a reboot I have a waiting-for-ssh-to-answer function in my .zshrc:

function wssh () {
local HOST=$1
local PORT=$1
if [[ -z $PORT ]]; then
echo -n "Polling host $HOST on port $PORT for ssh connection"
while ! nc -z -w 2 $HOST $PORT &>/dev/null; do
        for i in `jot 2 1`; do
                echo -n "."
                sleep 2
echo "\nConnection establihed!"
ssh -p$PORT $HOST $@
share|improve this answer

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.

share|improve this answer
Change it to xdg-open and it should work on any XDG-compliant desktop environment. –  Juliano Jun 8 '09 at 0:59

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

share|improve this answer
...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
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.

share|improve this answer
alias uab='unison -rsync -auto -batch'

I use unison to sync my settings, read/undread newsgroup mesages, etc.

share|improve this answer
alias viewpw='aespipe -d < ~/.passwd.aes > ~/.passwd.dec && more ~/.passwd.dec && shred -u ~/.passwd.dec'

How I remember all my passwords...

share|improve this answer

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

share|improve this answer
alias memusage='ps -o rss,command -waxc | sort -n'
alias ssq='svn status -q'
alias up='cd ..'
share|improve this answer
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; }
share|improve this answer
alias svndiff='svn diff --diff-cmd=colordiff'
alias df='df -h'

The first line uses colordiff to colorize svn diff output

share|improve this answer

Most of our servers don't listen to SSH on a public VLAN. I can't be bothered to keep a tunnel open on my laptop when away from the office:

zugzug() { ssh -A -p <non_standard_port> -t <proxy_server> ssh $1; }

While it's a function and not an alias, I find it invaluable.

share|improve this answer

a few choice LAMP related snippets:

apache: current activity

alias apache_status='watch -n1 "/etc/init.d/httpd fullstatus | egrep \"GET|POST\""'

apache: check config and gracefully restart if all ok

alias graceful='/etc/init.d/httpd configtest && /etc/init.d/httpd graceful && echo Gracefully Done'

get process info

alias pinfo='/root/procinfo'

redhat release info

alias about='cat /etc/redhat-release && cat /proc/version && uname -a' alias

start vim in insert mode (contraversial!)

alias vi='vim -c startinsert'

monitor drbd activity and state of bonded NICs

alias cluster='watch -d -n0.2 cat /proc/drbd /proc/net/bonding/bond0'
share|improve this answer

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 :)
share|improve this answer

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

share|improve this answer

to display squid log file in real time

alias proxy='tail -f /usr/local/squid/var/logs/access.log'

share|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 "

share|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.

share|improve this answer