Monday, May 10, 2010

Add alias to commands in Terminal

Alias can be very useful. One example is that if you enter the remove command on wrong file by mistake it would be damn difficult to obtain it back. Because removal of file through terminal doesn't send the file to Trash.

so each time you can run a command to remove as

but again by mistake you can type rm file.txt

what you can do is add an alias for rm command. i.e, you can make the default "rm" command as "rm -i"

This is how to do it.

go to home directry i.e, /home/ankit

by running ls -a command you will see .bashrc file.

we need to edit this file.

now press i to enter into insert mode of vi editor.


Now save this file by pressing esc and then :wq

finally to make changes active enter

Note: if at any time you mess up in editing the file with vi editor then press esc and then :w!. it will take you out without saving the changes.

now when you run rm command again you will be asked to verify it.

similarly you can alias to many other commands and thus make your life easier on terminal!
Also think about the other uses of it!

No comments:

Copyright 2009 ENDEAVOR