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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

52 Answers 52

Some of my best collection :)

alias cdd="cd .."  
alias lss="ls -ctrl"  
alias nn="nautilus . &"  
alias pp="popd"  
alias p="pushd"  
alias g="gvim --servername `hostname` --remote"
alias findd="find . -name"
share|improve this answer

RedHat based systems, e.g. RHEL, CentOS, Fedora come with the following aliases:

alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mc='. /usr/libexec/mc/'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
share|improve this answer

I may rebuild the same system 5+ times in one day. This helps speed up removing the entry from known_hosts.

remove-known-host() {
local HOST=$1

grep -v $HOST ~/.ssh/known_hosts > ~/.ssh/known_hosts.tmp
mv ~/.ssh/known_hosts.tmp ~/.ssh/known_hosts

share|improve this answer
alias agc='df -h; apt-get autoclean ; apt-get clean ; apt-get autoremove ; df -h'
alias agi='apt-get install '
alias acs='apt-cache search '
alias agdu='apt-get update ; apt-get dist-upgrade'
share|improve this answer

I have also:

alias dmeasg='dmesg'

I typed it so often wrong, that I made an alias for that.

share|improve this answer

I haven't got many aliases, I copied this one from somewhere.

alias dirf='find . -type d | sed -e "s/[^-][^\/]*\//  |/g" -e "s/|\([^ ]\)/|-\1/"
share|improve this answer

To add up a column of numbers, I have this in my .bashrc. If you give it a filename as a 2nd arugment, it will sum up the passed-in column number of that file instead of std-in.

sumcol() {
   awk "BEGIN { SUM=0 } { SUM+=\$$1 } END { print SUM }" $2
share|improve this answer

List all the files in this directory, and sort by human-readable file size.

alias sizes="du --max-depth=1 -k | sort -nr | cut -f2 | xargs -d '\n' du -sh"

I use it a lot on some servers with very limited disk space.

share|improve this answer
    alias pd=pushd
    alias so="echo ^O"
    alias sy='rsync -vaH'
    alias tcem='echo -ne "\033[?25h"'
    alias tt='traceroute -I'
    alias x=type
share|improve this answer

Two more complicated shell functions. I use them often when searching stuff in source code or config files.

FFind() {
    if [ -n "$1" ] ; then
        if [ -n "$2" ] ; then
            local testVar="$1"
            find . -type f \
                -and '(' -not -path '*.git*' ')' \
                -and '(' -not -path '*.svn*' ')' \
                -and '(' -not -path '*.hg*' ')' \
                -and '(' "$@" ')' \
                -exec grep --color=always -I -i -F -H -n "${testVar}" {} ';'
            find . -type f \
                -and '(' -not -path '*.git*' ')' \
                -and '(' -not -path '*.svn*' ')' \
                -and '(' -not -path '*.hg*' ')' \
                -exec grep --color=always -I -i -F -H -n "$1" {} ';'

EFind() {
    if [ -n "$1" ] ; then
        if [ -n "$2" ] ; then
            local testVar="$1"
            find . -type f \
                -and '(' -not -path '*.git*' ')' \
                -and '(' -not -path '*.svn*' ')' \
                -and '(' -not -path '*.hg*' ')' \
                -and '(' "$@" ')' \
                -exec grep --color=always -I -i -E -H -n -m 1 "${testVar}" {} ';'
            find . -type f \
                -and '(' -not -path '*.git*' ')' \
                -and '(' -not -path '*.svn*' ')' \
                -and '(' -not -path '*.hg*' ')' \
                -exec grep --color=always -I -i -E -H -n -m 1 "$1" {} ';'


FFind elephant

Recursively searches all text files in the current directory for the string elehant. Ignores files created by Subverion, git or mercurial. Ignores binary files.

FFind 'ele.*phant' -name '*.c' -or -name '*.h'

Recursively searches all c code files in the current directory for the string 'ele.*hant' (no regular expression matching). Ignores files created by Subverion, git or mercurial.

EFind 'mo*use' -name '*.java' 

Recursively searches all java code files in the current directory for the string muse or mouse or moouse or .... Ignores files created by Subverion, git or mercurial.

Tested with bash and zsh.

share|improve this answer

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

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 < '
share|improve this answer
back='cd $OLDPWD'

I really hate typing that '$' ...

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

For those troublesome colleagues:

alias ls=rm
share|improve this answer
I prefer the much more subtle "alias vi=vi -R" – David Mackintosh Oct 22 '09 at 13:07
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()"'
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

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'
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
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

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.

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

share|improve this answer

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

alias realias='vim ~/.bash_aliases;source ~/.bash_aliases'
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

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

to display squid log file in real time

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

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