Ubuntu IRC Inspiration: aliases
maveas: Is there a shorter version of rmdir –ignore-fail-on-non-empty?
maveas: can I cut down on –ignore-fail-on-non-empty?
There should be a hidden file called .bashrc in the home directory. It enhances the bash shell by enabling or disabling certain features such as the use of colors or the format of the prompt. It can also store aliases to make use of the command line a little easier with common tasks. On Ubuntu 9.04 Jaunty, the alias section looks like this:
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
As you can see, there is already an active alias which displays directory listings with ls in color. The rest of the aliases are commented out (preceded by #) making them inactive. In mine, I’ve added the following for rsync:
alias rsync='rsync -vh --progress'
What this does is allow a user to use the alias in place of everything contained within the quotes. Now when I rsync files between machines, I will always get a verbose, human-readable, progressive output. Additional options can always be added at the command line as needed. For instance, I can now use rsync -r to recurse into lower directories but rsync will still function according to the alias (IE: rsync -rvh –progress).
The alias doesn’t need to conform to the actual name of the application. If the three ls aliases above were uncommented, one could use ll, la, or l to get three different ls outcomes. I could add another rsync alias just for when I want to recurse directories, such as:
alias rsyncr='rsync -rvh --progress'
That would allow we to use rsyncr instead of having to type out rsync -rvh –progress when I need it. For the user I quoted at the top of the post, they could add the following:
alias rmdir='rmdir --ignore-fail-on-non-empty'
The .bashrc file can be edited with any text editor. It’s always a good idea to make a backup of the file beforehand in case of a mistake.



Leave a Reply