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.
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”
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.
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…
I always use “rm -f” anyway.
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
………………………..
Instead of typing “/bin/rm” you can always type “\rm” to escape the alias…
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
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..
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”
Here’s an alias for you…
alias crap_article=”history>article.txt”
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.
rofl to death !
the best thing I read today man !
can’t stop laughing !!
_THANK_YOU_!
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 -“
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
🙂
alias rm=’rm -i’
for Windows(TM) nostalgics
# 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\”}}'”
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.
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
yeah it can, the only difference is that the windows security model is way more complex then the UNIX one.