How do I find all files containing specific text on Linux?

The grep command, which means global regular expression print, remains amongst the most versatile commands in a Linux terminal environment. It happens to be an immensely powerful program that lends users the ability to sort input based on complex rules, thus rendering it a fairly popular link across numerous command chains. The grep command is primarily used to search text or search any given file for lines containing a match to the supplied words/strings. By default, grep displays the matching lines, and it may be used to search for lines of text matching one/many regular expressions in a fuss-free, and it outputs only the matching lines.

The basic grep command syntax

grep 'word' filename
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName



Do the following:

grep -rnw '/path/to/somewhere/' -e 'pattern'
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.

Along with these, --exclude--include--exclude-dir flags could be used for efficient searching:

  • This will only search through those files which have .c or .h extensions:
    grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
  • This will exclude searching all the files ending with .o extension:
    grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
  • For directories it’s possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:
    grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

For more options check man grep.


Setting up Unicorn with Nginx on Ruby on Rails

In this blog post, I am going to tell you, How to configure Unicorn web sever on top of Nginx. I Assume that you already installed Ruby and Ruby on Rails on your production OS(operating system) and a sample application working fine.!! If not, follow my previous blog post Setup Ruby On Rails on Ubuntu.

Nginx and Unicorn

To get you started, Let’s install Nginx first by using apt-get package manager.

$ sudo apt-get install nginx

Sometime you get ERROR because your machine packages are not upto date. Run apt-get update to downloads the package lists from the repositories and “updates” them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

$ sudo apt-get update

Once your nignx will install, you command window will prompt:

Setting up nginx-full (1.2.1-2.2ubuntu0.1) ...
Setting up nginx (1.2.1-2.2ubuntu0.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for sgml-base ...
Updating the super catalog...

At this point switch to /etc/nginx/ and /etc/nginx/sites-available configuration directory and have a look to nginx.conf and default respective configuration file. It’s self explanatory under commented in-lines. If still you need more details. I will recommend you to check wiki.nginx for more info.

While the server configuration it’s always better to create separate user(which we have more control over than nobody) for security reasons and increased control by using below command:

$ sudo useradd -s /sbin/nologin -r nginx
$ sudo usermod -a -G web nginx

Starting/stopping/restarting Nginx is pretty straight forward.

$ sudo service nginx start/restart/stop

Now let’s install Unicorn, Unicorn is distributed as ruby gem So you can install vi ruby gem.

$ gem install unicorn

Once Unicorn installed successfully. We need to create two configuration file.

1.Replace /etc/nginx/sites-available/ default file with below code:

upstream shop {
  server unix:/tmp/ fail_timeout=0;

server {
   listen 80;# default deferred;
   server_name localhost;
   root /var/www/shop/public;
   try_files $uri/index.html $uri @shop;

location @shop {
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header Host $http_host;
   proxy_redirect off;
   proxy_pass http://shop;

error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
   keepalive_timeout 10;

2. Create a unicorn.config file in your Rails application configuration file with below code:

working_directory "/var/www/shop"
pid "/var/www/shop/tmp/pids/"
stderr_path "/var/www/shop/log/unicorn.log"
stdout_path "/var/www/shop/log/unicorn.log"

listen “/tmp/”
worker_processes 2
timeout 30

You have to tweak a few things to set the right paths in above configuration. Change “/var/www/shop” with your rails application directory.

In my case my Rails application is in /var/www/ with shop name.

Before start your rails application, make sure to include unicorn gem in your Gemfile and run bundle to install all dependencies.

That’s all.

Setup Ruby On Rails on Ubuntu

Installation of Ruby on Rails for Production server is pretty straight forward. Below are the relevant steps.


sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev


sudo apt-get update
 sudo apt-get install ruby1.9.3

Note you can install latest Ruby too.


 sudo apt-get install ruby-dev
 sudo apt-get install build-essential g++
 sudo gem install railsconfigure rails application with nginx and unicorn


 sudo apt-get install libsqlite3-dev

If you passed all above steps without any ERROR, Now it’s time to create a rails demo application OR SCP existing one and test it out.

Below is the steps to create new rails application

 rails new demo
 cd demo
 uncomment therubyracer gem in Gemfile
 sudo apt-get install build-essential g++
 bundle install
 rails g scaffold order name:string
 rake db:create
 rake db:migrate

Open config/routes file and uncomment root ‘welcome/index’ and replaced with ‘orders/index’

$rm -rf public/index

That’s all, Now run your Rails application.

Netbeans add ruby platform

Install RVM and Ruby version what ever you want .

Once you done with ruby installation,
From terminal type below command..

$rvm use 1.9.1
$cd /home/alan/programs/netbeans_6_8/bin ***or wherever your netbeans is installed

I hope, it will help.
For details visit



error: AttributeError(“‘module’ object has no attribute ‘binary'”, )

I was facing same issues, After couple of hours google search i found this solutions.

We need to do some update in /home/maisa/workspace/Fang-of-Mongo/fangofmongo/fom

In your case may it differ, Here /home/maisa/workspace is my working directory where, I cloned Fang-of-Mongo.

Go to Fang-of-Mongo/fangofmongo/fom folder and open file and these changes.

That’s working fine for me. Enjoy..!!!!!!!!!!!!!!!1

Install NetBeans IDE on Ubuntu 11.10

1. Make sure, You Added PPA repository to my Ubuntu.

sudo add-apt-repository ppa:ferramroberto/java

2.After adding PPA, update your system apt:

sudo apt-get update

3.Install the Java Development Kit:

sudo apt-get install sun-java6-jdk

If you have problem with java installation , take a look to install-java-and-java-browser-plugin-ubantu-11-10 .

4. Go to the folder where you want to download NetBeans and download by typing:


5.Give yourself permissions to execute the install script you have just downloaded:

chmod u+x

6. Now run netbeans:


Just do next as window, and click desktop icon to start NetBeans:

That’s it. Enjoy……………

PostgreSQL installation in Ubuntu 12.04

PostgreSQL is a powerful and reliable object-relational database system. It’s a great alternative for MySQL. It is as easy to set up, performs better and offers far more features.

1. Make sure you already have install python-software-properties

$sudo apt-get install python-software-properties

2.Add PPA repository to my Ubuntu.

$sudo add-apt-repository ppa:pitti/postgresql

3. After adding PPA, update your system apt:

$sudo apt-get update

4.Finally install postgresql-9.1:

$sudo apt-get install postgresql

if you having any error, make sure you already install libpq-dev.The libpq-dev package is for compiling wrappers/clients against libpq.

$sudo apt-get install postgresql-9.1 libpq-dev

5.Now check it out installation is successful or…..

$ locate postgresql

6. If done!!!

Check the install version.

$psql -V

7.Now let’s take look to postgres console

$su postgres

7(a) Setup Root User ‘posrgres’

$sudo passwd postgres

give the postgres user a (unix) password,Now we can switch to the user postgres using command

$ su postgres

8. That’s it for postgers installation. If you want to access postgres from remote, Mean localhost. You need to perform some addition setting to postgres conf file.

First we edit the file postgresql.conf:

$ cd /etc/postgresql/9.1/main

List all file in main folder

$ ls -la

total 80
drwxr-xr-x 2 postgres postgres 4096 2012-05-17 18:05 .
drwxr-xr-x 3 postgres postgres 4096 2012-04-07 12:44 ..
-rw-r–r– 1 postgres postgres 316 2012-04-07 12:44 environment
-rw-r–r– 1 postgres postgres 143 2012-04-07 12:44 pg_ctl.conf
-rw-r—– 1 postgres postgres 4653 2012-05-17 18:05 pg_hba.conf
-rw-r—– 1 postgres postgres 4649 2012-04-09 19:29 pg_hba.conf.bak.original
-rw-r—– 1 postgres postgres 1636 2012-04-07 12:44 pg_ident.conf
-rw-r–r– 1 postgres postgres 19235 2012-04-07 12:44 postgresql.conf
-rw-r–r– 1 postgres postgres 19235 2012-04-09 19:29 postgresql.conf.bak.original
-rw-r–r– 1 postgres postgres 378 2012-04-07 12:44 start.conf

I have already back of config file, you need to make back up for further need

$ cp pg_hba.conf pg_hba.conf.bak.original
$ cp postgresql.conf postgresql.conf.bak.original

9. Make changes to pg_hba.conf (authetification methods).

host    all         all       trust          # md5 -> trust

10.You make change in config file, So once restart you postgres

$sudo /etc/init.d/postgresql restart
*Restarting PostgreSQL 9.0 database server
That’s it. Enjoy………