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

Is there anything that you can't live without and will make my life SO much easier? Here are some that I use ('diskspace' & 'folders' are particularly handy).

# some more ls aliases
alias ll='ls -alh'
alias la='ls -A'
alias l='ls -CFlh'
alias woo='fortune'
alias lsd="ls -alF | grep /$"

# This is GOLD for finding out what is taking so much space on your drives!
alias diskspace="du -S | sort -n -r |more"

# Command line mplayer movie watching for the win.
alias mp="mplayer -fs"

# Show me the size (sorted) of only the folders in this directory
alias folders="find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn"

# This will keep you sane when you're about to smash the keyboard again.
alias frak="fortune"

# This is where you put your hand rolled scripts (remember to chmod them)

locked by HopelessN00b Dec 3 '14 at 1:31

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as not constructive by RobM, EEAA, Scott Pack, HopelessN00b, mdpc Oct 31 '12 at 16:50

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

This should be community wiki – Toro May 6 '09 at 14:53
Turned into community wiki. Enjoy. – gyaresu May 6 '09 at 22:50
piped to more? I bet you'd be happier with less or less -F – derobert May 7 '09 at 16:28
Just in case anyone is interested, there is a service that allows you to browse, build a list and source your aliases: – Sam152 Apr 22 '13 at 0:13

39 Answers 39

up vote 81 down vote accepted

I have a little script that extracts archives, I found it somewhere on the net:

extract () {
   if [ -f $1 ] ; then
       case $1 in
           *.tar.bz2)   tar xvjf $1    ;;
           *.tar.gz)    tar xvzf $1    ;;
           *.bz2)       bunzip2 $1     ;;
           *.rar)       unrar x $1       ;;
           *.gz)        gunzip $1      ;;
           *.tar)       tar xvf $1     ;;
           *.tbz2)      tar xvjf $1    ;;
           *.tgz)       tar xvzf $1    ;;
           *.zip)       unzip $1       ;;
           *.Z)         uncompress $1  ;;
           *.7z)        7z x $1        ;;
           *)           echo "don't know how to extract '$1'..." ;;
       echo "'$1' is not a valid file!"
Nice. Again though, there's that IDE/Vim argument regarding know the commands from memory. Fantastic bit of script though. Definitely going in the .bashrc Cheers! – gyaresu May 5 '09 at 1:07
There's a nice and simple linux command called "unp", the Unpacker that does this and more. – Sander Marechal May 10 '09 at 23:33
Newer versions of tar detect automatically the archive type, so can extract all supported formats by just 'tar xvf'. – Prof. Moriarty Jun 8 '10 at 17:47

How many aliases to fortune do you need, anyway?

I like to make a cdd alias that takes me to wherever I'm presently most likely to be working on that server.

PATH redefinition really belongs in .bash_profile, not .bashrc.

On a server where I routinely use a large set of screens, my .bashrc will have:

alias s1="screen -dr chaos1"
alias s2="screen -dr chaos2"
alias s3="screen -dr chaos3"
# ... and so on

(The screens were set up with, for example, screen -U -S chaos1.)

@chaos "How many aliases to fortune do you need, anyway?". woo for win. frak(and alternate spellings) for fail. – gyaresu May 4 '09 at 0:56
@Ian Kelling: What I'm actually saying is that operations that should be performed once per login belong in .bash_profile and operations that should be performed once per shell instantiation belong in .bashrc. – chaos May 4 '09 at 11:43

I used to set these up all over the place but then realized that it was better to just remember how to do them 'manually' because it meant I would 1) fully understand what was going on and 2) have access to these capabilities even if my custom .bashrc wasn't installed.

The only thing I use aliases for these days are to cut down on repetitive typing of really long lines (eg. alias myhost='ssh -T screen -dAr' )

Agreed regarding memorising long useful commands. I find though that I'm running 'diskspace' fairly often on runaway servers (i.e. php is coredumping all over the place). – gyaresu May 4 '09 at 1:24
It's easy enough to deploy your custom configuration on systems you regularly use, though. – Tobu Nov 15 '10 at 17:59

Among other things, I set some defaults for less, prevent accidentally closing my terminal and enable forward navigation through history:

# ignore case, long prompt, exit if it fits on one screen, allow colors for ls and grep colors
export LESS="-iMFXR"

# must press ctrl-D 2+1 times to exit shell
export IGNOREEOF="2"

# allow ctrl-S for history navigation (with ctrl-R)
stty -ixon

Since I use so many different machines, my .bashrc always sets the command prompt to include, among other things, the name of the server I am currently logged into. This way, when I am three levels deep in telnet/ssh, I don't type the wrong thing in the wrong window. It really sucks to rm -rf . in the wrong window! (Note: At home, telnet is disabled on all machines. At work, ssh is not always enabled and I don't have root access to very many machines.)

I have a script ~/bin/setprompt that is executed by my .bashrc, which contains:

SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"

# Throw it all together 

This script sets the prompt to the host name followed by :) if the last command was successful and :( if the last command failed.

I also show the status in my prompt, but keep the numeric value and colour it red if non-zero, otherwise green. – pgs Jun 1 '09 at 10:01

The one liners and tiny scripts out there could go on forever. I recommend man bash and writing things yourself. Some good short bash stuff at Heres a few things.

#use extra globing features. See man bash, search extglob.
shopt -s extglob
#include .files when globbing.
shopt -s dotglob
#When a glob expands to nothing, make it an empty string instead of the literal characters.
shopt -s nullglob
# fix spelling errors for cd, only in interactive shell
shopt -s cdspell
# vi mode
set -o vi

s() { # do sudo, or sudo the last command if no argument given
    if [[ $# == 0 ]]; then
    	sudo $(history -p '!!')
    	sudo "$@"

prompt_command() {
    p=$PWD  # p is much easier to type in interactive shells
    # a special IFS should be limited to 1 liners or inside scripts.
    # Otherwise it only causes mistakes.
    unset IFS

# smart advanced completion, download from
if [[ -f $HOME/local/bin/bash_completion ]]; then
    . $HOME/local/bin/bash_completion

extract () { # extract files. Ignore files with improper extensions.
    local x
    ee() { # echo and execute
    	echo "$@"
    	$1 "$2"
    for x in "$@"; do
    	[[ -f $x ]] || continue
    	case "$x" in
    		*.tar.bz2 | *.tbz2 )	ee "tar xvjf" "$x"	;;
    		*.tar.gz | *.tgz ) ee "tar xvzf" "$x"	;;
    		*.bz2 )				ee "bunzip2" "$x"	;;
    		*.rar )				ee "unrar x" "$x"   ;;
    		*.gz )				ee "gunzip" "$x"    ;;
    		*.tar )				ee "tar xvf" "$x"   ;;
    		*.zip )				ee "unzip" "$x"     ;;
    		*.Z )				ee "uncompress" "$x" ;;
    		*.7z )				ee "7z x" "$x"      ;;
I like your history -p trick. – Tobu Jul 2 '10 at 10:50

I have a few bits:

# stop the pc speaker ever annoying me :)
setterm -bfreq 0

# don't put duplicate lines in the history. See bash(1) for more options
# ... and ignore same sucessive entries.

# Expand the history size

# commands with leading space do not get added to history

# am I on the internet?
alias p4='ping -c 4'

# pwsafe
alias pw='pwsafe -p'

# ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias lt='ls -laptr' #oldest first sort
alias labc='ls -lap' #alphabetical sort

# cd aliases
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

# cd into the old directory
alias bd='cd "$OLDPWD"'

# install a package and automatically respond yes to confirmation prompt
alias ins="sudo aptitude install"

# remove a package and its configuration files
alias remp="sudo aptitude purge"

# search for a package - apt-cache and aptitude search in different ways
# so have both
alias searchc="apt-cache search"
alias search="aptitude search"
alias show="aptitude show"
Your HISTCONTROL lines override each other, since it's just a shell variable. ignoreboth combines ignorespace and ignoredups. – Annika Backstrom May 27 '09 at 14:34
Try cd - instead of bd – ptman Jul 2 '10 at 9:15

These are my favorites:

export HISTFILESIZE=1000000000
export HISTSIZE=1000000

I like having a command-line history that never forgets.

Unfortunately, awhile back I launched a shell from cron which didn't read .bashrc somehow, and chopped everything down to 500 lines, destroying over a years' history. So I recommend these go in /etc/bashrc.


I've had this in my .bashrc for a while and I've found it helpful. If you are sshing in to the box, is starts screen automatically when you login, that way when your network connection gets interrupted or whatever, you don't lose whatever you were doing. It should be placed at the end.

if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x  -a "${SSH_TTY:-x}" != x ]
[ -d $HOME/lib/screen-logs ] || mkdir -p $HOME/lib/screen-logs

sleep 1
screen -U -RR && exit 0

echo "Screen failed! continuing with normal bash startup"

I would echo @pjz's comment about knowing things manually rather than setting them up. Especially if you access numerous machines, like I always seem to do.

So one I definitely know is set -o vi because I know the vi-editing commands in bash and I don't know the emacs ones (besides, Ctrl+A interferes with screen). On my own boxes, I put that in .bashrc

I also find I have to include export EDITOR=vim because a number of recent distros default to nano which is most annoying to be thrown into by a utility that needs you to edit something, when I was expecting vi. :-/

I also alter my prompt. I found a long long time ago that adding the last error code is just useful enough that I like it. And I like the full pathname in the prompt. And the current screen number, too. And it just makes sense to include the current user and hostname. My prompt is PS1='\u@\h $PWD $WINDOW [$?] \$ '


From Automating Linux and Unix Administration by Kirk Bauer (great book!)

PS1='\n[\u@\h]: \w\n$?> '

The newline at the beginning is mine, I like to have a clear line between the previous output and the prompt. The rest is:

\u = username

\h = host

\w = working directory

$? = last return code


I compile a number of things manually into $HOME/local so I have this little snippet:

for prog in $HOME/local/*
    if [ -d "$prog/bin" ]; then
        export PATH=$prog/bin:$PATH
    if [ -d "$prog/include" ]; then
        export C_INCLUDE_PATH=$prog/include:$C_INCLUDE_PATH
    if [ -d "$prog/lib" ]; then
        export LD_LIBRARY_PATH=$prog/lib:$LD_LIBRARY_PATH
        export LIBRARY_PATH=$prog/lib:$LIBRARY_PATH
    if [ -d "$prog/man" ]; then
        export MANPATH=$prog/man:$MANPATH
    if [ -d "$prog/share/man" ]; then
        export MANPATH=$prog/share/man:$MANPATH

I also have my IRC client on my server running in screen so I have this (not a .bashrc thing, but still useful)

#!/usr/bin/env bash

RUNNING=`screen -ls | grep irc`
if [ "" = "$RUNNING" ]; then
   screen -S irc irssi
   screen -dr irc

this is an awesome resource for this:

show us your .bashrc


I sometimes have to use a Solaris system at work.

However the system is centrally managed via Puppet, including the password file (which includes the shell setting).

My .bashrc therefore reads something like:

exec /bin/tcsh



To have colors for All grep commands such as grep, egrep and zgrep, I have the following in my .bashrc

export GREP_OPTIONS='--color=auto'

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"

History can be very useful, but by default on most distributions your history is blown away by each shell exiting, and it doesn't hold much to begin with. I like to have 10,000 lines of history:

export HISTFILESIZE=20000
export HISTSIZE=10000
shopt -s histappend
# Combine multiline commands into one in history
shopt -s cmdhist
# Ignore duplicates, ls without options and builtin commands
export HISTIGNORE="&:ls:[bf]g:exit"

That way, if I know that I've done something before but can't remember the specifics, a quick history | grep foo will help jog my memory.

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 "
    eval $cmd

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

If you need to specify a delimiter (e.g., awk -F: for /etc/passwd), this function obviously can't handle that. The slightly-overhauled version in this gist can handle arbitrary awk arguments before the field number (but still requires input from stdin).

I use the ssh alias and ssh keys too... it makes every so easy – devin May 30 '09 at 15:14
+1 for the history control tips. – Rene Saarsoo Jun 25 '09 at 22:39
you can put hostname aliases in .ssh/config to the same effect. In this case, add an entry 'Host cloudius' with 'username dinomite' – Sirex Oct 30 '12 at 23:16

A little tip for Bash if you are a sysadmin and work with root privileges a lot:

shopt -o noclobber

This will prevent you from accidentally destroying the content of an already existing file if you redirect output (>filename). You can always force overwriting with >|filename.


Have bash check to see if the window size has changed (prevents line-editing from going weird if you resize your terminal window)

shopt -s checkwinsize

This is my favourite. Causes bash to append to history instead of overwriting it. Typically when you launch bash, it loads history into memory, and when you close it it writes it out. This means that if you load two shells, use both, then close both, the one you closed last overwrites all changes.

This snippet causes it to first of all only append changes (instead of overwriting with the whole buffer), and then to cause it to, after every command, write out changes. In effect, you get a live updating .bash_history, so if you start a new terminal, you have all the commands from your other running sessions' history.

shopt -s histappend
PROMPT_COMMAND='history -a'

I use my bashrc on numerous machines, so i've got this little snippet to make sure LS is colourized. This will fix it on OSX machines, maybe even *BSD if you adjust the uname line.

if [ "$TERM" != "dumb" ]; then
    if [ `uname` == "Darwin" ]; then
       alias ls='ls -G'
       eval "`dircolors -b`"
       alias ls='ls --color=auto'

Also, I've got a command to backup a file, useful if your about to change a config file and want to make a quick copy before hand.

bu () { cp $1 ~/.backup/`basename $1`-`date +%Y%m%d%H%M`.backup ; }

Color for manpages in less makes manpages a little easier to read:

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

Colored manpages can also be obtained by installing most and using it as MANPAGER env variable. If you want to use this pager not only for man, use the PAGER variable, like this:

export PAGER="/usr/bin/most -s"

. $HOME/bin/git-prompt/


A few aliases I use to take the edge off of the daily CLI grind...

# I find myself doing this a lot
alias hg='history | grep '

# Likewise this, plus I'm always mistyping it...
alias findy='find . -name'

# sometimes you're just not sure you want to delete something...
alias trash='mv -t ~/.local/share/Trash/files --backup=t'

alias vb='vim ~/.bashrc'

# I find typing 'cd ..' less than optimal
alias up='cd ..'
alias 2up='cd ../../'
alias 3up='cd ../../../'
alias 4up='cd ../../../../'

# re-map caps lock key to be Ctrl
# (works on Linux, at least)
xmodmap -e "remove lock = Caps_Lock"
xmodmap -e "add control = Caps_Lock"

# helpful history settings:
export HISTCONTROL=ignoredups
export HISTCONTROL=ignoreboth
export HISTIGNORE=ls:ll:la:l:cd:pwd:exit:mc:su:df:clear:cls

To fix window size in GNU screen after resize:

shopt -s checkwinsize

To show the permissions on a directory, shortcut ls -ld:

alias lld='ls -ld'

History viewing:

alias h='history | zgrep'

And contents of my zgrep script, which I couldn't figure out how to cram directly into the alias:

grep "${*-.}"

I'm addicted to screen, and I use the following shortcuts for SSHing to machines. With this script, I type p hostname to SSH to a host and run screen, or o hostname to do the same but run screen on the local machine.

First a script that connects to an SSH server of the same name as the script you're running. I call this simple_ssh:

BASENAME=$(basename $0)

if [ "$SCREEN" = "1" ]; then
	export SCREEN=0
	exec screen -RD scr$BASENAME -s $0
elif [ "$SCREEN" = "2" ]; then
	exec ssh $BASENAME "$@" -t 'screen -RD'

exec ssh $BASENAME "$@"

Symlink this to mars in your path and mars becomes a shortcut for ssh mars:

adam@pluto:bin$ ln -s simple_ssh mars
adam@pluto:bin$ mars

The $SCREEN environment variable lets you automatically execute GNU screen with the connection. SCREEN=1 runs screen locally (say, if screen is not installed on the host) and SCREEN=2 runs it on the host itself.

Use a couple aliases to shortcut this:

alias o='SCREEN=1 exec'
alias p='SCREEN=2 exec'

Use a script to create symlinks for all your hosts given an ~/.ssh/config file like this:

Host mars
    User abackstrom

The script, sshconfig2simplessh:


BASENAME=$(basename "$0")
USAGE="Usage: $BASENAME /path/to/bin"

if [ -z "$1" ] ; then
	echo $USAGE
	exit 0

if [ ! -d "$1" ] ; then
	echo "$1 is not a directory" >&2
	exit 1

cd "$1"

HOSTS=$(grep '^Host ' < ~/.ssh/config | cut -d' ' -f2)

for HOST in $HOSTS ; do
	if [ ! -e "$HOST" ]; then
		echo ln -s simple_ssh "$HOST"
		ln -s simple_ssh "$HOST"

I have the following in my bashrc

function __setprompt {
  local BLUE="\[\033[0;34m\]"
  local NO_COLOUR="\[\033[0m\]"
  local SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
  local SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
  if [ $SSH2_IP ] || [ $SSH_IP ] ; then
    local SSH_FLAG="@\h"
  PS1="$BLUE[\$(date +%H:%M)][\u$SSH_FLAG:\w]\\$ $NO_COLOUR"

On a local machine it looks like:


but on a remote (through ssh) it is:


This is one of my favorites:

alias ssh='if [ "$(ssh-add -l)" = "The agent has no identities." ]; then ssh-add; fi; /usr/bin/ssh "$@"'

If i've forgotten to authenticate, it lets me do so without having to waste my typing doing ssh-add after the ssh session.


GPG encrypted bashrc

I'm sure we all have things we'd like to put in our bashrc that we don't want easily readable by sudoers. My solution to this is:

if [ -f ~/.bash_private.gpg ]; then
   eval "$(gpg --decrypt ~/.bash_private.gpg 2>/dev/null)"

I have a GPG agent that makes it so I only have to enter my private key's password once every few hours. You still have to have some trust in the users of the system because your variable, functions, and aliases that you define could be extracted from RAM. However, I use this mainly for my laptop. If it gets stolen, I don't want someone easily seeing things like:

alias MYsql='mysql -uadmin -psecret'
wglatest(){ wget -O; }

Tail all logs in /var/log

alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"

Here are a few of my favorites:

alias ls='ls -F --color=auto'
alias l='ls'
alias ll='ls -ahl'
alias ..='cd ..'
alias ...='cd ../..'
alias mv='mv -i'

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

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

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