Tips related to

Tuesday, 23 March 2010

Linux commands

By default most of the commands you can execute are placed in the /bin folder. However, you can add another folder where your user will look for commands from. Lets do that ;)
(if in any of the following cases you get "permission denied" error, then do the same action, but logged as root.)



(first create that folder, in this example ~/.bin)
$mkdir ~/.bin
(next, lets add that folder to PATH via ~/.bashrc)
$nano ~/.bashrc
(in the ~/.bashrc file, simply add the following line)
$export PATH=$PATH:~/.bin



Great, you have your own folder in which your shells will look for commands whenever you type a command. Now we need to only make bash scripts for the commands in the folder. Note that we could have just made the scripts in the default /bin folder, but for neatness, it's good not to mix your own commands with the system's default ones.

How to make the scripts?


Simply create a file using your favourite text editor, named with the name of the command you want to create, in which you will put all the commands that you want to be executed, each one in a new line, and make that file executable.
So lets make a testscript file that will print out on the screen "it worked!".
Create a file named "testscript" in the .bin folder and put the following line in it:


echo "it worked!"

Save the file. To make it executable run the following command as root:

#chmod +x testscript

Now relogin, or just in a new terminal window test it ;)

$testscript
it worked!

Examples of useful things you can do with what you just learned.
Ever wished synchronizing and updating eix was simpler? Just make a script called synch, or whatever with the commands you wish it to cover:


emerge --sync
update-eix


Just make sure you edit root's .bashrc too, cause the above commands work for root users only. And don't forget to chmod +x it ;)

Ever thought that typing "mplayer -fps 15 tv:// -tv driver=v4l2:device=/dev/v4l/video0", or whatever command you're using for mplayer to use your webcam was too hard to remember?
Make a script called "camera" with that command in.

So you can simplify all your work you do often that includes multiple commands.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | 100 Web Hosting