span.fullpost {display:inline;}

Wednesday, October 1, 2008

BASH SCRIPT

Keeping it simple: You know by now that "rm" removes a file, permanently !
Wouldn't it be nice if we could move it to the recycle bin with a simple command instead ?

We're gonna make that command and call it: "del"
( YES ! making our own commands ! )

First a little script:


CODE
$ vi /usr/bin/del


"i"
Here is the text for the script:


QUOTE (Text @ Script)

#!/bin/bash
mv $1 ~/Desktop/Trash
#End script



<>
"ZZ"

Make it executable


CODE
# chmod 0775 /usr/bin/del



Now if we do


CODE
$ del tessst


( It will execute the script and do the same as: )


CODE
$ mv tessst /home/bruno/Desktop/Trash



Sure this was a very short example, a 3 line script, it only holds one command, but you could put as many lines in the script as you want and execute it with a four letter word.
If there are more commands in the script it will execute them in the order that they are noted down.

Because /usr/bin is in your "path" you only have to type "del" to execute it.

If you have to do complicated commands in a certain order on a regular basis, make a little bash script, put it in your "path" and give it a name that's easy to remember.

Next time we'll make a simple backup script, to backup and gzip the contents of your /home directory.

0 comments:

Tutorialsland By - Templates4all | Free Blogger and web Templates
Free Website templatesFree Flash TemplatesFree joomla templatesSEO Web Design AgencyMusic Videos OnlineFree Wordpress Themes Templatesfreethemes4all.comFree Blog TemplatesLast NewsFree CMS TemplatesFree CSS TemplatesSoccer Videos OnlineFree Wordpress ThemesFree Web Templates