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.

I found this article discussing a quick way to sort your bash history and see which commands you use the most:

cut -f1 -d" " .bash_history | sort | uniq -c | sort -nr | head -n 30

It really opens your eyes as to which tasks you should create aliases for and which ones you should cronjob away completely.

I'd love to see a ServerFault list of recommended command line aliases that save you time on the job. What have you got?

Between us, I'll bet we can save every user who reads this post at least 10 minutes a day. (Minus the first day wherein they waste all of their time reading ServerFault instead of doing their job of course!)

share|improve this question
    
Nice. But what exactly is your question? –  innaM May 6 '09 at 12:08
    
I've edited the question to make my intentions more clear, I'm asking other ServerFault users to tell me about their favorite/most used aliases. –  Jax May 6 '09 at 12:10
4  
Community Wiki? –  Adam Gibbins May 6 '09 at 12:56
    
For the record, on Super User there's superuser.com/questions/7083/useful-command-line-aliases with loads of useful Bash aliases –  Jonik Jul 7 '10 at 8:06
    
See also: serverfault.com/questions/15365/… –  Aaron Copley Dec 7 '10 at 18:28
add comment

13 Answers

up vote 7 down vote accepted

I deal with a lot of different machines so one of my favorites is aliases for each machine that I need to frequently SSH to:

alias claudius="ssh dinomite@claudius"

It is also useful to setup a good .ssh/config and ssh keys to make hopping amongst machines even easier.

Another one of my favorite aliases is for moving up directories:

alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

And some for commonly used variations of ls (and typos):

alias ll="ls -l"
alias lo="ls -o"alias lh="ls -lh"
alias la="ls -la"
alias sl="ls"
alias l="ls"
alias s="ls"

I almost always want egrep:

alias grep="egrep"

Get man pages from all sections

alias man="man -a"

I often found myself piping output through awk in order to get a certain column of the output, as in df -h | awk '{print $2}' to find the size of each of my disks. To make this easier, I created a function fawk in my .bashrc:

function fawk {
    first="awk '{print "
    last="}'"
    cmd="${first}\$${1}${last}"
    eval $cmd
}

I can now run df -h|fawk 2 which saves a good bit of typing.

I work with a lot of Perl and need to know the versions of modules installed on a system:

function perlmodver {
    perl -M$1 -e 'print "Version " .
        $ARGV[0]->VERSION . " of " . $ARGV[0] .
        " is installed.\n"' $1
}
share|improve this answer
add comment

My favorite of all times:

alias server_name='ssh -v -l username ip_address'

It doesn't need explanation, does it? :-)

share|improve this answer
5  
Isn't that what's .ssh/config is for :-P Host server_name Hostname 1.2.3.4 User username etc. –  vartec May 6 '09 at 12:23
    
Using bash_completion and tab,tab seems to work just fine for me, instead of setting up a bunch of ssh aliases –  Clayton Stanley Jun 4 '12 at 4:08
add comment

I usually like to type everything, because I'm afraid I'll forget all about the commands I'm using in no time. I know I may be wrong, but I don't think I'd know as much about the system if I had just pasted every command in Commandlinefu into my .bashrc.

Note that I'm not saying that I'm the greatest and I know everything there is to know about Linux, far from that, I'm just saying I like to learn, and remember what I've learned by using.

That's not to say I don't appreciate how time saving aliases are (specially for larger functions, but then you have to see if a script isn't better), but, personally, I don't like to use them (at least no always).

That being said, Commandlinefu has a special tag for aliases. It's worth looking.

Also I think this is a good one:

   alias less='less -FSRX'

This will only use less if the output is bigger than the screen.

share|improve this answer
add comment

I have to admit I have a few like this..

alias sl=ls

To try and combat my typos :-)

I also have

alias aliases='xterm -e vim ~/.bash_aliases;reload'
alias reload='. ~/.bash_aliases'

So its nice and simple to add new ones.

share|improve this answer
add comment
alias cd..='cd ..'
share|improve this answer
add comment

alias lt='ls -lhart'

  • l=long : h=human readable sizes : a=all : r=reverse sort : t=time sort
  • Puts the newest file at the bottom, right above the prompt

alias active='grep -v -e "^$" -e"^ *#"'

  • shows only lines that are not blank or commented out
  • example: active /etc/httpd/conf/httpd.conf

alias svi='sudo vim'

alias scr='screen -Rd'

share|improve this answer
    
Nice, especially sudo vim –  astropanic Dec 7 '10 at 13:49
add comment
for host in `awk '{ print $1 }' ~/.hostsILogIntoAllTheTime`; do
  alias $host='ssx '$host
done

Type the hostname to logon to the host. Note: ssx is an alias itself:

ssx='ssh -Y'

Combined with shared keys, it's pretty slick.

share|improve this answer
add comment

I find annoying to put the whole apt-get and apt-cache things in debian / *buntu, especially with sudo prefix, so I have:

alias apti='sudo apt-get install'
alias aptr='sudo apt-get remove'
alias apts='apt-cache search'
share|improve this answer
add comment

create .tar.gz

alias tarc="tar czvf"

extract .tar.gz

alias tarx="tar xzvf"

list .tar.gz

alias tart="tar tzvf"
share|improve this answer
add comment

I found this page looking for a way to make an alias to show me the nth column of a csv (tsv actually) file using awk. The fawk function above was almost exactly what I wanted. I modified slightly to add an optional second argument, the filename, so I can use it like awk normally rather than only through a pipe.

function fawk {
    first="awk '{print "
    last="}' $2"
    cmd="${first}\$${1}${last}"
    echo $cmd
    eval $cmd
}

Thanks!

share|improve this answer
add comment

This is not an alias, but seeing people who aliases ssh connections, might be useful.

Openssh package has a binary called ssh-argv0 that works via symlinks.

So, if you do something like this:

sudo ln -s /usr/bin/ssh-argv0 /usr/local/bin/user@ssh.server.com

Having /usr/local/bin in the $PATH, now you can connect as user "user" to ssh.server.com writing this in a shell prompt:

 $ user@ssh.server.com
share|improve this answer
add comment

+1 for Drew Stephens answer. The only one he didn't cover that I also use is to alias the various dot files I need to access on a regular basis like:

alias dotz='vi ~/.zshrc'

Take it a step further with an on-the-fly add-alias function:

function add-alias {
echo "alias $1=\047$2\047" >> ~/.zshrc
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.