Friday, November 13, 2009

Recover deleted files in ubuntu

Well..... you can recover some of the files that you deleted intentionally or accidently for ever.(that which you dont find in the trash)


There are two tools that can be used..
1. scalpel
2 foremost

install any of them..
eg

sudo apt-get install scalpel

after the package is installed..you have to edit the config file to specify the type of file that you have to recover

sudo gedit /etc/scalpel/scalpel.conf

now uncomment the types of files that you have to recover.

and then identify the address of the address of the drive from which you have to recover the file.

this can be found out from gparted
say for example sda3

now type

scalpel /dev/sda3 -o output

here you can specify a path instead of output.
by the above command it creates a folder in the directory in which you have issued the command


similarly you can use the foremost also this purpose.



sudo apt-get install foremost

now type sudo foremost -t jpeg -i /dev/sda3

Saturday, October 31, 2009

Installing lamp (apache mysql php) in linux

Everything can be done easily through the command line

sudo apt-get install apache2

this will install apache server on your system

can be checked by typing
http://localhost in your browser window

if you get a message It Works! then its success

now to install php
type

sudo apt-get install php5 libapache2-mod-php5

and now restart the apache to see if its working

type

sudo /etc/init.d/apache2 restart

now create a file say with the name testphp.php in your www folder(/var/www)

you should open it as root so
type: sudo gedit /var/www/testphp.php

and type


phpinfo();
?>


now if you type http://localhost/testphp.php in your browser you will get the file giving the information on php installed on your system

Once again open up Terminal and then copy/paste this line:
sudo apt-get install mysql-server

(optional). In order for other computers on your network to view the server you have created, you must

first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line

bind-address = 127.0.0.1


And change the 127.0.0.1 to your IP address.

To change the password of the root user

type in terminal, this will take you to the mysql console
mysql -u root

Following that copy/paste this line:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

(Make sure to change yourpassword to a password of your choice.)

To intall phpMyAdmin

To install a program called phpMyAdmin which is an easy tool to edit databases.Copy/paste the following line into Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file
entitled php.ini. To open it type the following:

gksudo gedit /etc/php5/apache2/php.ini

Now we are going to have to uncomment the following line by taking out the semicolon (;).
Change this line:

;extension=mysql.so

To look like this:

extension=mysql.so


Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart

Split and Join files in liinux

split is the command used to split large files in linux


let us split the file

music.mp3

inorder to split it to 1mb each the following command is used

split -b 1M music.mp3

here this -b refers to splitting files based on bytes, files can be splitted based on lines too it is by giving -l

this will create files named xaa xab xac ........

this can later be combined to a single file called music-combined.mp3 as

cat xa* > music-combined.mp3


more information in this regard can be obtained my refferring to the man file of split


man split

Tuesday, October 20, 2009

To read from keyboard - java

use java.io package

import java.io.*;

next you'll need an InputStreamReader to read from the System.in stream
Code:
InputStreamReader isr = new InputStreamReader(System.in) );
afterwards, you'll need a BufferedReader to store the stream

Code:
BufferedReader br = new BufferedReader(isr);

use the readLine() method to get a string

Code:
String sampleString = br.readLine();
put it all together

Code:
import java.io.*;
class RandomClass
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
String sample = br.readLine()
}

Thursday, October 1, 2009

CRONTAB automate your task....

So how many of you have heard of crontab in linux.

Its something which is very useful. It automates tasks....

suppose you want to execute a task at sometime in the future (only if the system is switched on), all you need to do is add the command in the crontab.

in order to install a crontab just type crontab -e
this will open you a file to write commands with some other fields too

m h dom mon dow command

The above given is the order in which you have to make the entry in the cron..
m stands for minute of the hour
h for hour of the day(24 hour clock)
dom stands for the day of the month
mon stands for the month
dow stands for the day of the week
command this is where you specify the command which is to be executed

so as an example

34 6 9 4 * mkdir /home/username/file

the above command makes a directory named file on 9th of April at 6 hours and 34 minutes in the folder /home/username


you can also specify a range too

32-50 * 9 4 * command

the above command is executed on April 9th in every minute from 32-50 minutes in all the 24 mangagers. hours...


---the above post is incomplete, will be updated soon---

Sunday, September 27, 2009

Automatic ssh

I am sharing the information which i got after searching through several blogs and forums .
In Linux platform-
suppose there are two machines A and B

and you want to connect from machine A to machine B without being prompted for a password.
since you want to connect from A to machine B , machine B needs to verify the identity of machine A.
so what we do is add the identity of machine A to machine B.

so here are the steps.
1 In machine A, you have to create a public/private key pair
for that
first enter the .ssh folder in the home folder
type "ssh-keygen -t dsa" in the terminal

you get a message
"Generating public/private dsa key pair."
and a prompt
"Enter file in which to save the key (/home/username/.ssh/id_dsa): "
just press Enter as blank will do
and another prompt
"Enter passphrase (empty for no passphrase): "
again press Enter as we use blank for this too...

and another prompt
"Enter same passphrase again"
again press Enter as we use blank for this to

now if you check the directory in which you are in, you can see two files id_dsa and id_dsa.pub

Now copy the file id_dsa.pub to the machine B.
you may use "scp id_dsa.pub B:" command where B is 'username@ip'

In machine B.
check if a file named "authorized_keys" is present in .ssh folder in B's home folder
this is a hidden folder in the home directory.

In order to display hidden files and folders you may use the command
"ls -a"

Even if the file "authorized_keys" is not present in the .ssh folder, you need not worry
now in order to add the identity of A to B, follow the steps

Append the contents of file "id_dsa.pub" which you just copied now, to the "authorized_keys" file

if you are in your home folder...
type the command "cat id_dsa.pub >> .ssh/authorized_keys"

And that's all , now if you try to ssh or scp from machine A to machine B it will not ask you a password.

if you want to login in to any other system from A you can append the id_dsa.pub in the authorized_keys file of the remote system

deleting id_dsa.pub does not cause any problem. but make sure that id_dsa file is not deleted.