141
votes

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)
PATH="$HOME/bin:$PATH"
8
  • 3
    This should be community wiki
    – Toro
    May 6, 2009 at 14:53
  • 1
    Turned into community wiki. Enjoy.
    – Gareth
    May 6, 2009 at 22:50
  • 4
    piped to more? I bet you'd be happier with less or less -F
    – derobert
    May 7, 2009 at 16:28
  • Except that there is that "sort" before the more, since sort needs the full input, the less -F would just let you see the sorting faster, and I bet it's pretty dang fast.
    – GreenKiwi
    May 26, 2009 at 13:56
  • 1
    Just in case anyone is interested, there is a service that allows you to browse, build a list and source your aliases: alias.sh
    – Sam152
    Apr 22, 2013 at 0:13

39 Answers 39

1
2
1
vote
IP_ADDRESS_BASH=`ip addr | grep -w inet | gawk '{if (NR==2) {$0=$2; gsub(/\//," "); print $1;}}'`
PS1="\h $IP_ADDRESS_BASH \w % "

And then it displays IP of your machine that you just logged to.

1
vote
# vi ~/.bashrc # red/green terminal colors regarding exit code
export PROMPT_COMMAND='PS1="`
if [[ \$? = "0" ]];
then echo "\\[\\033[0;32m\\]";
else echo "\\[\\033[0;31m\\]";
fi`[\u@\h \w]\[\e[m\] "'
export PS1
1
  • Will this alter the $? variable after running the command or does it still have the value produced by the last command run? Jun 28, 2012 at 5:00
1
vote
mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

ecb () { emacsclient -n -a emacs $@ & } # open in emacsclient in the background
ecp () { emacsclient -n $(which $@) & } # open a given file found in a $PATH in emacsclient
ecr () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; } # start emacsclient or emacs and open the file as root

eCf () { emacs --batch --eval "(byte-compile-file \"$@\")"; } # byte-compile file
eCa () { emacs --batch --eval "(batch-byte-compile-if-not-done)" *.el; } # byte-compile all el files in the current directory and it's children
0
votes

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:

%!/bin/bash
exec /bin/tcsh

:)

0
votes

. $HOME/bin/git-prompt/git-prompt.sh

0
votes

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
2
  • You could make 1up print a mushroom in ASCII art, just for kicks ;)
    – David Z
    Jun 30, 2009 at 19:00
  • While almost all of the answers refer to tweaking history, I haven't seen any which enable timestamping which can be useful. export HISTTIMEFORMAT='%F %T '
    – cclark
    Aug 1, 2012 at 17:45
0
votes

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:

#!/bin/sh
grep "${*-.}"
0
votes

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:

#!/bin/sh
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'
fi

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
adam@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
    HostName mars.example.com
    User abackstrom

The script, sshconfig2simplessh:

#!/bin/sh

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

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

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

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"
    fi
done
0
votes

Fedora

alias install=sudo yum install

Debian

alias install=sudo apt-get update && sudo apt-get install
1
2

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