Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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 professional 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.

17  
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
show 2 more comments

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.

share|improve this answer
add comment

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
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
show 1 more comment

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
show 1 more comment

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

share|improve this answer
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
show 2 more comments

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
add comment
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
add comment
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.

EDIT:

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
5  
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
show 5 more comments

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  
+1 for changing sudo vi <somefile> to sudoedit <somefile! +more if I could –  Kevin M Aug 4 '09 at 15:45
show 2 more comments

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>"
        else
                mkdir -p $1
                cd $1
        fi
}

# 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
add comment

For those troublesome colleagues:

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

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

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

share|improve this answer
show 1 more comment

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 < '
share|improve this answer
add comment
alias l='ls --color=auto -lsah'
alias ..='cd ..'

I miss it very often on other systems

share|improve this answer
add comment
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
show 1 more comment
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
add comment

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
add comment

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
add comment

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

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

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
add comment
if [ "$(uname)"="darwin" ]; then
  EDITOR=mate
  PATH=$PATH:~/.bin
  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'
fi

if [ "$(uname)" = "SunOS" ]; then
  alias ls='ls -F'
  alias e='vim'
  alias subash='pfexec bash'
fi
share|improve this answer
show 1 more comment

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
1  
Change it to xdg-open and it should work on any XDG-compliant desktop environment. –  Juliano Jun 8 '09 at 0:59
add comment

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
show 1 more comment
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 http://192.168.1.1/wancfg.cmd?action=view | 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
add comment

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