Linked by Tony Steidler-Dennison on Thu 10th Jul 2008 16:37 UTC
Linux The Linux desktop has come a long, long way, but there are still times when I have to use the command line. (I am a hardcore user, after all.) But even though I'm used to typing, spending hours upon hours with my fingers at the keyboard, I still grow tired of typing the same commands over and over. To reduce that tedium, I always add aliases to my .bashrc file.
Order by: Score:
some more
by jonas on Thu 10th Jul 2008 16:48 UTC
jonas
Member since:
2005-07-08

some that i've found useful and that were popular at my previous workplace:

Make common administration tasks go through sudo without having to type sudo:

alias dpkg="sudo dpkg"
alias apt-get="sudo apt-get"
alias modprobe="sudo modprobe"

Serve files from CWD via a webserver:

alias serve="python2.5 -m SimpleHTTPServer"

Color stuff; grep w/ less that doesn't mess it up

alias ls="ls --color=auto -F"
alias grep="grep --color=auto"
alias less="less -R"

open up files in existing vim session

alias rvim="gvim --remote"

Reply Score: 1

rm alias
by anomie on Thu 10th Jul 2008 16:54 UTC
anomie
Member since:
2007-02-26

I don't agree with the rm -i alias. I've gotten into the habit of explicitly using mv -i and rm -i (when using wildcards). If a user assumes rm will provide interactive feedback - i.e. because it's aliased that way on a couple systems - s/he may be very surprised when working on a system that does not.

Reply Score: 4

RE: rm alias
by big_gie on Thu 10th Jul 2008 16:58 UTC in reply to "rm alias"
big_gie Member since:
2006-01-04

yeah that's true. But this is slower to type... and CLI is all about speed!
I remember someone suggesting a different alias for "rm -i" like rmi...

Reply Score: 1

RE: rm alias
by Nico57 on Thu 10th Jul 2008 18:11 UTC in reply to "rm alias"
Nico57 Member since:
2006-12-18

I always use "rm -f" anyway. ;)

Reply Score: 2

RE: rm alias
by J-freebsd_98 on Fri 11th Jul 2008 10:14 UTC in reply to "rm alias"
J-freebsd_98 Member since:
2006-01-01

i've aliased rm to essentially "what ???"
so I have to type the full path /bin/rm
and habitually use -iv "always"
......................
the time it takes to type "/bin/rm -iv"
seems to prevent the hurriedly-typing
errors (rm oops I meant cp) which
otherwise could occur.
HAS WORKED for over 3 years great here
.............................

Reply Score: 1

RE[2]: rm alias
by big_gie on Fri 11th Jul 2008 14:36 UTC in reply to "RE: rm alias"
big_gie Member since:
2006-01-04

Instead of typing "/bin/rm" you can always type "\rm" to escape the alias...

Reply Score: 1

Mine
by big_gie on Thu 10th Jul 2008 16:56 UTC
big_gie
Member since:
2006-01-04

Instead of ssh aliases, I edit ~/.ssh/config to something similar:
host NAME
Hostname IPADDRESS
Port PORT
RemoteForward REMOTEPORT localhost:LOCALPORT
and then just "ssh NAME"

And here are my most important aliases:
fichiers=/home/me/files
alias cdh='cd $fichiers'
alias cdt='cd $fichiers/downloads'
[...]

alias burn_dvd_iso='growisofs -speed=2 -dvd-compat -Z /dev/dvdrw='
alias nano='nano -w'
alias screen="screen -U"
alias df="df -h --print-type"
alias du="du -h --max-depth=1 ."
alias free='free -m'
alias grpe='grep'
alias top="htop"
alias untar="tar -xvf"

# Find process
alias pss="ps aux | grep -i"

alias dc='cd'
alias sl='ls'
alias sls='ls'
alias l='ls'
alias rm='rm -i'
lsbase='/bin/ls -h --group-directories-first --color=auto'
alias ls="$lsbase -gG"
alias lsg="$lsbase -l"
alias la="$lsbase -la"

alias su='sudo -i'
alias shutdown="sudo shutdown"
alias halt="sudo halt"
alias nanos='sudo nano'
alias snano='sudo nano'
alias svim='sudo vim'
alias cpufreq-set='sudo cpufreq-set'

And now functions, instead of alias. Allows you to give arguments:
# Diff svn workdir to head with kompare:
sdiff() {
svn diff $1 | kompare -o -
}

I can't live without these ;)

Edited 2008-07-10 16:59 UTC

Reply Score: 3

My .bashrc
by sappyvcv on Thu 10th Jul 2008 17:45 UTC
sappyvcv
Member since:
2005-07-06

I have a lot of aliases to cd to specific directions. I also have:

# Can't even remember what it all does. N is probably line numbers
alias less='less -x4 -R -N'

# Needs 256color support in the terminal
PSCOLOR="214" # or another color, each server i use has a different color
export PS1="\033[38;5;${PSCOLOR}m\h\033[38;5;231m:\033[38;5;${PSCOLOR}m w\n\033[38;5;231m#\033[0m "

I also have a bunch on my .vimrc as well..

Reply Score: 2

put some of them in $home/.inputrc
by cobbaut on Thu 10th Jul 2008 17:56 UTC
cobbaut
Member since:
2005-10-23

Nice tips, but i prefer to put them in my ~/.inputrc (linked to a function key)

sample:
~# grep apt .inputrc
"\e[17~": "aptitude update && aptitude safe-upgrade\n"

Reply Score: 3

..step 2, profit!
by robinh on Thu 10th Jul 2008 18:06 UTC
robinh
Member since:
2006-12-19

Here's an alias for you...

alias crap_article="history>article.txt"

Reply Score: 1

RE: ..step 2, profit!
by libray on Thu 10th Jul 2008 19:16 UTC in reply to "..step 2, profit!"
libray Member since:
2005-08-27

alias remove_crap_article="find ~/ -type f -exec perl -p -i -e 's/http:\/\/blogs.techrepublic.com.com\/10things\/\?p=352\&tag= rbxccnbtr1//' {} \;"


Use this every time you mistakingly visit that article.

Reply Score: 2

RE: ..step 2, profit!
by gnemmi on Thu 10th Jul 2008 20:14 UTC in reply to "..step 2, profit!"
gnemmi Member since:
2006-08-17

rofl to death !
the best thing I read today man !
can't stop laughing !!

_THANK_YOU_!

Reply Score: 1

Directory aliases
by amjith on Thu 10th Jul 2008 18:33 UTC
amjith
Member since:
2005-07-08

I find the following two aliases to be very useful

List only directories:
alias lsd="ls -d */"

take back to previous directory (cd - takes you to the previous directory):

alias p="cd -"

Reply Score: 1

Aliases for FreeBSD
by Doc Pain on Fri 11th Jul 2008 02:10 UTC
Doc Pain
Member since:
2006-10-08

Here are some nice aliases for use with FreeBSD.

The obvious ls:
alias ls 'ls -FG'
alias ll 'ls -laFG'
setenv LSCOLORS ExGxdxdxCxDxDxBxBxegeg

Playing with the floppy disk:
alias flop 'tar cvjf /dev/fd0'
alias unflop 'tar xvjf /dev/fd0'

Creating CDs:
alias burndata 'cdrecord -v -eject -tao -data'
alias burnaudio 'cdrecord -v -eject -dao -audio'

Unmounting and ejecting (inconsequent implementation):
alias ucd 'umount /media/cdrom && cdcontrol eject'
alias udvd 'umount /media/dvd && cdcontrol eject'
alias uwr 'umount /media/writer && cdcontrol -f /dev/acd1 eject'
alias ujaz 'umount /media/jaz && camcontrol eject 0:4:0'
alias upd 'umount /media/pd && camcontrol eject 0:1:0'
alias upcd 'umount /media/pcd && cdcontrol -f /dev/cd0 eject'

They should work with bash, as well as with csh (/etc/csh.cshrc).

I will definitely keep a copy of the article and the corresponding discussion due to the many inspirations for further aliasing.

Remember the recursion!
$ alias alias alias
Too dangerous to alias that
:-)

Reply Score: 2

Comment by petrasl
by petrasl on Fri 11th Jul 2008 12:23 UTC
petrasl
Member since:
2006-01-03

alias rm='rm -i'

for Windows(TM) nostalgics

Reply Score: 1

Some of my bash aliases
by supersteve1440 on Sat 12th Jul 2008 03:52 UTC
supersteve1440
Member since:
2006-12-31

# print the boot time

alias boottime="date --date=@$(grep btime /proc/stat | gawk '{print $2}') +'%a %b %d, %r'"

# recursizely clean backup files (*~)

alias clean='find -type f \( -name "*~" -or -name ".*~" \) -print0 | xargs --null --no-run-if-empty rm --verbose'

alias clean1='find -maxdepth 1 -type f \( -name "*~" -or -name ".*~" \) -print0 | xargs --null --no-run-if-empty rm --verbose'

alias clean2='find -mindepth 2 -type f \( -name "*~" -or -name ".*~" \) -print0 | xargs --null --no-run-if-empty rm --verbose'

alias d='ls -hop --color'

# move items to a trash directory (~/Trash.$USER)

alias del='mv --verbose --backup=simple --suffix=$(date +".(%F_%T)") --target-directory=$HOME/Trash.$USER/'

# list dir sizes

alias dir-sizes='du --separate-dirs --bytes | sort --numeric-sort'

# list file sizes

alias file-sizes='find -type f -printf "%s %p\n" | sort --numeric-sort'

# fancy formatting for ps

alias ps1='ps --forest --headers -e --sort pid'

alias ps2='ps --forest --headers -U root -u root -N --sort pid'

alias ps3='ps --forest --headers -U $USER -u $USER --sort pid'

# recursively remove empty folders
# (while there are empty folders, remove empty folders)


alias rmdirempty='while [[ -n $(find -mindepth 1 -empty -type d -printf 1 -quit) ]] ; do find -mindepth 1 -empty -type d -print0 | xargs --null --no-run-if-empty rmdir --verbose ; done'

# remove empty files

alias rmempty='find -empty -type f -print0 | xargs --null --no-run-if-empty rm --verbose'

# remove old files (uses -mtime -1)
# be careful!


alias rmold='find -type f -daystart -not -mtime -1 -print0 | xargs --null --no-run-if-empty rm --verbose'

# remove orphans

alias rmorphan='find -xtype l -print0 | xargs --null --no-run-if-empty rm --verbose'

# empty trash directory
# print the number of items deleted

alias trash="rm --force --recursive --verbose ~/Trash.$USER/* ~/Trash.$USER/.*[^.]* | wc --lines | gawk '{if(\$1 == 1) {print \"1 item removed\"} else {print \$1 \" items removed\"}}'"

Reply Score: 0

One I always use...
by UltraZelda64 on Sat 12th Jul 2008 04:41 UTC
UltraZelda64
Member since:
2006-12-05

alias clh="history -c && exit"

This will allow you to clear the bash history and then send the exit command by simply typing "clh". If you've got a terminal opened and have used su to become root or another user, typing this in will clear root's (or whoever you've switched to) bash history and then return you to your original user. If you're yourself (ie. haven't used su to become root), it will clear your own history and close the terminal. Of course, it has to be in the .bashrc files of any user who wants to use it (in my case, both my own personal home and /root). This will also completely wipe out the history, which may not be desired by everyone.

Reply Score: 1

powershell? nah
by netpython on Sat 12th Jul 2008 13:15 UTC
netpython
Member since:
2005-07-06

if test "$UID" != "0"; then
umask 077
fi
if test "$UID" != "0"; then
chmod go-rwx -R $HOME/.
fi
if test "$UID" != "0"; then
chmod +t -R $HOME/*
fi

in /etc/profile

Can MS powershell do the same?

Enough said.

Edited 2008-07-12 13:16 UTC

Reply Score: 2

RE: powershell? nah
by google_ninja on Sat 12th Jul 2008 13:33 UTC in reply to "powershell? nah"
google_ninja Member since:
2006-02-05

yeah it can, the only difference is that the windows security model is way more complex then the UNIX one.

Reply Score: 2