Wednesday, December 29, 2010

How to use multiple line comments in bash scripting

All single line comments in bash begin with # symbol, except for the first line (#!/bin/bash)
# this is an example of single line comment.

You can use HERE DOCUMENT feature to create multiple line comment

welcome to the
this is an example of
multiple line comment
in bash

Tuesday, December 28, 2010

How to debug a bash script in Linux

To debug a bash script, you need to run a shell script with -x option from the command line itself:
bash -x scriptname
bash -xv scriptname

You can also modify shebang line to run an entire script in debugging mode.

#!/bin/bash -x
echo "Hello ${USER}"
echo "Today is $(date)"

Monday, December 27, 2010

How to execute a scirpt in Linux

A shell script can be executed using the following syntax
chmod +x

You can also run the script directly without setting the script execute permission

In the last example we are using . (dot) or source command which reads and executes commands from filename in the current shell.
When a script is executed using either the bash command or the source (.) command, you don't have to set execute permission on script.


Monday, December 13, 2010

How to run a C++ program in linux

Install g++ (Ubuntu) or gcc-c++ (RedHat or fedora) package using 
apt-get or yum.
sudo apt-get install g++
yum install gcc-c++
Write a C++ program using your favorite editor.
emacs hello_world.cpp
vi hello_world.cpp
gedit hello_world.cpp
 #include <iostream>  
  using namespace std; 
  int main() { 
      cout << "Hello World!\n";
      return 0;
The following command will compile your program 
and create an executable called a.out
   g++ hello_world.cpp
The following command will execute your program.
Congratulations! You are done!

Friday, December 10, 2010

How to avoid writing sudo every time

If you are a sudoer and want to aovid writing sudo every time (like sudo commandname), just invoke a shell as root
sudo bash
Then you can execute all the commands as root.

**!! when you are finished do not forget to exit from the shell

Wednesday, December 8, 2010

How to install Flash Player for Mozilla firefox web browser

*Download the latest Flash Player from Adobe web site.

*Select version to download

     YUM for linux
     .tar.gz for linux
     .rpm for linux  

     .deb for Ubuntu
     APT for Ubuntu

1. YUM for linux (RedHat, fedora)
install the downloaded .rpm file using rpm command.
rpm -ivh rpmfile.rpm
this will install adobe repository on your system.
now you can use yum command to install flash player.
yum install flash-plugin

2. .tar.gz for linux (for any distribution)
extract the .tar.gz file using tar command
tar xvf tarfile.tar.gz
you will get a file named Copy this file to the mozilla plugins directory.
cp /usr/lib/mozilla/plugins/
change the permissions of the file if required.
Restart the firefox browser.

3. .rpm for linux (for RedHat, fedora)
install the .rpm file using rpm command
rpm -ivh rpmfile.rpm
verify the flash player plugin using the following command
ls /usr/lib/mozilla/plugins/
now restart the browser.

4. .deb for linux (Ubuntu)
install the .deb file using dpkg command
dpkg -i debfile.deb
verify the flash player plugin in mozilla/plugins directory.

5. APT for linux (Ubuntu)
install the .deb file using dpkg command
dpkg -i debfile.deb
this will install adobe repository on your system.
Now you can use the apt-get command to install flash player.
apt-get install flash-plugin.

Restart your web browser.

Wednesday, December 1, 2010

Output man pages as plain text with col

There is an easy way to convert man pages into simple, non-redundant text.
To save a copy of any man page to text simply type:

man command_name | col -b > output_file_name


man ls | col -b > grep.txt

This can be especially useful for larger man pages, as you can now open
and work with the text file in any GUI text editor.
There was an error in this gadget