Tuesday, December 4, 2007

Bash Aliases - Cool Trick

I spent part of the last couple days studying command-line stuff via LinuxCommand. They have several helpful example scripts and even walk you through developing a script to generate system information on your computer. I found it very helpful.

Another cool discovery was this thread in the forums on bash-aliases. Apparently, you can create a file with all your preferred command line shortcuts. All you have to do is save it under a particular filename (“bash_aliases”) and then un-comment a few lines in another script. I found this incredibly handy. Some of my favorite aliases are below.

Most of these are from the help thread (some I modified for my use):

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
Sets interactive mode ("Are you sure?") before copying, moving or deleting files
alias google=’firefox http://www.google.com/'
alias ubuntu-help='firefox http://ubuntuforums.org/'
Opens Google and the Ubuntu help forums in Firefox
alias ed-alias='gedit home/jessica/.bash_aliases'
Open alias file in text editor (original used nano text editor but I don’t like that one)
alias ls='ls --color=auto'
alias lal=’ls –al’
alias ll=’ls –l’
These are for listing files in a directory. The first automatically colors the files based on type and read-write permissions. The second is a shortcut for listing in long-format all the files in a directory including hidden files. The last one is for listing all files except hidden files in a directory in long-format.
alias today='date +"%A, %B %-d, %Y"'
Displays the date.

The other cool thing is that if you forget what your aliases are, you can just type ‘alias’ at the terminal and it lists all the aliases allowed (ie - in your ".bash_aliases" file).

After setting this up, I spent a little bit moving files around and changing the read-write permissions from the terminal. I think I’ll be spending a few hours a week until Christmas just working on my command-line skills. That way during my Christmas time-off, I can (hopefully) start to really work on my scripting.

No comments: