Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, May 17, 2014

Tip: Find and Replace a string in multiple files at onces by avoiding LTS (Leaning toothpick syndrome)

Linux Command:

$ grep -lR "oldString" -r | xargs sed -i 's/oldString/newString/g'


How to avoid LST.

If your oldString or newString contains character "/" (the delimiter), then Delimiter collision occurs, which cause to LST.  To avoid that, select another delimiter such as # or ? in sed command.

examples:

sed -i 's#oldString#newString#g'
sed -i 's?oldString?newString?g'




Saturday, May 25, 2013

Recovering your deleted files using - Foremost

I recently looking for data recovery tool to recover some files in my home folder. I was looking some recover tool for linux, and I found an interesting command line tool call Foremost.

Why is it so interesting ?

  • light weight and easy to install. 
  • Easy to use.
  • Built in file filters for fast recovery. ( e.g: jpg, zip, rar etc.)

How to install foremost.

Go to terminal and  type.

$ sudo apt-get install foremost


Recovering deleted jpgs files in partition

  1. First make an empty writable directory to save recover files in a partition other than that you are going to recover. ( let's say /recovery/data/ )
  2. Then run foremost.  I am going to recover my home partition ( let's say /dev/sda5).

  3. $ sudo foremost -t jpg -i /dev/sda5 -o /recovery/data

  4. Finally set user permission to /recovery/data/ to view image. type

  5. $ sudo chown YOUR_USER_NAME /recovery/data -R

Some important foremost command line arguments.
  • -i  :- partition/image to recover
  • -o :- location to store recovered files.
  • -t  :- built in file filter options.  you can give multiple filters by separating using commas. (e.g: for jpg and pdf: -t jpg,pdf ) 
  • -q :- quick mode.
 you can find more details about foremost in following locations.

  1. https://help.ubuntu.com/community/DataRecovery#Foremost
  2. http://linux.die.net/man/1/foremost

Monday, February 4, 2013

Easy steps to enable Finger Print Reader on Linux Mint / Ubuntu


Here I am using Linux Mint 14 ( Mint is very similar OS to Ubuntu) on Lenovo ThinkPad machine.

Step 1 - is your Finger print reader detected by system...?

First check whether your figer print reader is recognized or not by the system. for this open terminal and run command.

$ lsusb
  
It shows information about USB buses in the system and the devices connected to them. Then look for your finger print reader device. (My finger print reader device, Upek is listed in device list.)

.. 
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 147e:2020 Upek 
Bus 001 Device 004: ID 04f2:b2eb Chicony Electronics Co., Ltd 
..

Step 2 -Installing fPrint

Use following commands to install fPrint.

$ sudo add-apt-repository ppa:fingerprint/fprint
$ sudo apt-get update
$ sudo apt-get install libpam-fprintd  

if Installation is success, the needed lines in common-auth should now be present. for that type following command in terminal

$ grep fprint /etc/pam.d/common-auth

you should observe similar output like this,

auth [success=2 default=ignore] pam_fprintd.so 

Final (Fun) Step - configure fPrint

Now run

$ fprintd-enroll

swipe your right index finger until process is completed.

Using device /net/reactivated/Fprint/Device/0
Enrolling right index finger.
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-completed

Now you should be able to authenticate (Login, Terminal,  Lock screen, and everywhere ) by swiping your right index finger.

see how it works on terminal authentication.


( Note: If finger print fails, then system automatically prompt you to enter password. )

Have fun...

Alternatives for fPrint:

I found another GUI client called Fingerprint GUI.( http://www.n-view.net/Appliance/fingerprint/ ) it has some advance features, compare to fPrint.


Reference: 

  1. http://www.thinkwiki.org/wiki/How_to_enable_integrated_fingerprint_reader_with_fprint

Friday, January 25, 2013

Ubuntu Tips - How Restore to Classic gnome desktop

1) Install gnome-session-fallback by typing following command.
 
sudo apt-get install gnome-session-fallback
 
2) Logout current session.
3) Select Ubuntu classic desktop from session chooser.
 
 
4) login :)

Sunday, February 19, 2012

[TIP] Use Linux Pipelines and Make your life easier

Suppose you want to get the history of your terminal (commands, that you have typed  in the terminal) and find out a command that you have used log time ago.

So you can simply use history command to list down command history and find it.

$ history

( By default Linux store only last 1000 history of your command line. you can find the history file and size of history by typing following command. you can change these values changing global profile value of the terminal. )

$ echo $HISTFILE 
$ echo $HISTSIZE

But if your list is bigger one you may need to do a search to find your command. 
for example you can use grep command to find it. See following command set.

$ history > history.txt 
$ grep -i "dpkg" history.txt
 1761  dpkg -s jflex
 1974  dpkg -s cup
$ rm history.txt

In first command it writes history into a text file. In the second line, it search for "dpkg" with ignoring the case in the history.txt and it shows the results in next two lines. After that in the 5th line it removes the history.txt file.

But we can do this easily using Linux pipelines. It generates no intermediate files and can obtain result using one line. here is the command.

$ history | grep -i "dpkg" 
 1761  dpkg -s jflex
 1974  dpkg -s cup 

This is a simple example that use Linux pipelines. You can use this for very complex stuffs.  Read this Wikipedia page to learn more on Linux pipelines.

Here is another example that use pipeline.

$ find . -name .svn | xargs rm -fr

this command removes all .svn directories in current path.( Also you can use non pipeline solution to do this. see following command )

find . -name .svn -exec rm -rf {} \;

Monday, May 16, 2011

Creating a “Document Root” directory in Home directory on Ubuntu. ( Part 2 )

 ~*~ From the Part 1 ~*~

Make user that you have installed php5 in your system. If not execute following commands in terminal.

 sudo apt-get install php5  
 sudo a2enmod php5  

first line install the php5 and second line enables PHP in apache server. Then restart apache using,

 sudo /etc/init.d/apache2 restart  

At this point, Apache and PHP are installed and ready to go.

I’m using ubuntu lucid distribution,
A recent update to the Lucid distribution, however, requires a slight change to /etc/apache2/mods-available/php5.conf to re-enable interpretation in users' home directories, but previous distributions do not require this change.

Open give file using your favorite text editor. Here I am using gedit.

 sudo gedit /etc/apache2/mods-available/php5.conf  

Comment out (or remove) the following lines:
 <ifmodule mod_userdir.c="">  
     <directory *="" home="" public_html="">  
       php_admin_value engine Off  
     </directory>  
 </ifmodule>  

After doing this change, restart apache using,
 sudo /etc/init.d/apache2 restart  

At this point, PHP should be successfully installed and working.

But this method will enable PHP for all user directories. For security reason this method is not a good practice. One thing can do is enable only for one user directory. To do this, follow this procedure.

Do not edit /etc/apache2/mods-available/php5.conf file and create a file (as root) called /etc/apache2/conf.d/php-in-homedirs.conf with the following contents:
 <ifmodule mod_userdir.c="">  
     <directory $username="" home="" public_html="">  
       php_admin_value engine On  
     </directory>  
 </ifmodule>  

Simply replace the $USERNAME with the user name of the user you wish to allow PHP access to. Also note that the <directory> section may be repeated as many times as is necessary. Save the file, and restart Apache with a
</directory>

 sudo /etc/init.d/apache2 restart  


And PHP should only be enabled for the users listed in this file.

~*~ End of Tutorial ~*~
=================================

Saturday, May 7, 2011

Creating a “Document Root” directory in Home directory on Ubuntu. ( Part 1 )

Introduction:


Generally Apache HTTP web server's document root is /var/www on Ubuntu/Debian Linux environment. (You can find the Document Root directive in /etc/apache2/sites-enabled/000-default.)

But in this post I am going to tell you how to create a document Root directory under your Home directory. This directory can be used same as /var/www directory. 

Advantages:

Since this directory is in your home directory you do not need to worry about permission issues. Also this might help for normal desktop user as well as web site developers to run/test their web sites or applications.

Here I’m using Apache Module userdir (http://httpd.apache.org/docs/2.0/mod/mod_userdir.html) to do this. Mooshak is a one of web based tool that uses this Apache userdir.

Tested Environment:

Ubuntu 10.10
Apache 2.2.17









Step1: Installing Apache2 and PHP5


First we need to install apache2 and php5 in your machine. If they are already installed ignore this step.

Open Linux terminal and type;
 $sudo apt-get install apache2 php5  

If you want to make sure that, apache2 is installed correctly; open a web browser and go to link http://localhost/ . If page get loaded correctly with saying it's working, that means you have installed apache2 correctly.

Also you can check the PHP installation using the terminal, just type in the terminal 

 $php -version  
 If it is correctly installed, you can see the installed version PHP in terminal.




Step 2: Creating a directory “public_html”

Create a directory under home directory called “public_html”. Here we are going to use this directory store our web pages.  Use any GUI base tool (file browser) or terminal for this. It doesn't matter. But do not use sudo command for this.

In terminal fist go in to your home directory and type  

 $mkdir public_html  




Step 3: Enable Apache module userdir

Here we are enabling an Apache module, called userdir.


 Note:  
   
You can find the available apache module under, /etc/apache2/mods-available/ .  
Also you can find the module enabled under /etc/apache2/mods-enabled/.   



To enable module userdir, type in terminal;


 $a2enmod userdir  

Another Way:
This is an alternative way to do same thing. That is symlink /etc/apache2/mods-available/userdir.load and /etc/apache2/mods-available/userdir.conf files to /etc/apache2/mods-enabled/ directory.
To do this, type in terminal;


 $cd /etc/apache2/mods-enabled/  
 $sudo ln -s ../mods-available/userdir.conf userdir.conf  
 $sudo ln -s ../mods-available/userdir.load userdir.load  

Restart Apache2 to enable userdir module.

 $sudo /etc/init.d/apache2 restart   

Congratulation, now you have enabled public_html document root directory in your machine. Note that you can access your websites in your home directory by a URL in the form http://localhost/~USER_NAME. For example if your user account name is USER, then you can access your website(s) in your public_html  directory via, http://localhost/~USER.

Testing the public_html directory using a sample html.
 

Open your favorite text editor, type  

 <html>  
   <body>  
     <h1>Hello World&lt;/h1>  
     <p>This is the default web page for your user directory.</p>  
   </body>  
 </html>   

Then save it as index.html in public_html directory.

Then open your browser and enter URL of the your user directory.  You can see the web page that we have created.



In Next Tutorial > How to enable PHP support in public_html 



~*~ goto Part 2 ~*~
=============================