Friday, June 17, 2011

Extract a gzip compressed tar archive in Linux

The version of tar in most Linux distributions supports gzip compression. This means that a gzipped tar file can be extracted in one simple command.


To extract the archive filename.tar.gz into the current directory:

tar xzf filename.tar.gz

If this fails, the version of tar may not support gzip compression. In this case, you can use the traditional two-stage command:
gzip -dc filename.tar.gz | tar xf -

http://www.tech-recipes.com/rx/138/extract-a-gzip-compressed-tar-archive-in-linux/

Thursday, April 21, 2011

Kill process in Linux

Q. How do I kill process in Linux?
A. Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.

Kill process using kill command under Linux/UNIX

kill command works under both Linux and UNIX/BSD like operating systems.

Step #1: First, you need to find out process PID (process id)

Use ps command or pidof command to find out process ID (PID). Syntax:
ps aux | grep processname
pidof processname

For example if process name is lighttpd, you can use any one of the following command to obtain process ID:
# ps aux | grep lighttpdOutput:
lighttpd  3486  0.0  0.1   4248  1432 ?        S    Jul31   0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
lighttpd  3492  0.0  0.5  13752  3936 ?        Ss   Jul31   0:00 /usr/bin/php5-cg
OR use pidof command which is use to find the process ID of a running program:
# pidof lighttpdOutput:
3486

Step #2: kill process using PID (process id)

Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486
OR
# kill -9 3486
Where,
  • -9 is special Kill signal, which will kill the process.

killall command examples

DO NOT USE killall command on UNIX system (Linux only command). You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin
As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).

http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/

Show All Running Processes in Linux

How do I see all running process in Linux?

You need to use the ps command. It provide information about the currently running processes, including their process identification numbers (PIDs). Both Linux and UNIX support ps command to display information about all running process. ps command gives a snapshot of the current processes. If you want a repetitive update of this status, use top command.

ps command

Type the following ps command to display all running process:
# ps aux | less
Where,
  • -A: select all processes
  • a: select all processes on a terminal, including those of other users
  • x: select processes without controlling ttys

Task: see every process on the system

# ps -A
# ps -e

Task: See every process except those running as root

# ps -U root -u root -N

Task: See process run by user vivek

# ps -u vivek

Task: top command

The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
# top

Task: display a tree of processes

pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.
$ pstree

Task: Print a process tree using ps

# ps -ejH
# ps axjf

Task: Get info about threads

Type the following command:
# ps -eLf
# ps axms

Task: Get security info

Type the following command:
# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

Task: Save Process Snapshot to a file

Type the following command:
# top -b -n1 > /tmp/process.log
Or you can email result to yourself:
# top -b -n1 | mail -s 'Process snapshot' you@example.com

Task: Lookup process

Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example display firefox process id:
$ pgrep firefox
Following command will list the process called sshd which is owned by root user.
$ pgrep -u root sshd

Say hello to htop and atop

htop is interactive process viewer just like top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines. Tasks related to processes (killing, renicing) can be done without entering their PIDs. To install htop type command:
# apt-get install htop
or
# yum install htop
Now type the htop command at the shell prompt:
# htop

atop program

The program atop is an interactive monitor to view the load on a Linux system. It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network. It also shows which processes are responsible for the indicated load with respect to cpu- and memory load on process level; disk- and network load is only shown per process if a kernel patch has been installed. Type the following command to start atop:
# atop


http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/

Thursday, March 3, 2011

installing IntelliJ IDEA on ubuntu

To Install IntelliJ IDEA 8.1 on ubuntu

Following are the steps :

1.first you need install java for you need to run below command on terminal.

admin@smartproteam~$ sudo apt-get install sun-java6-jdk

2.Now you need to download IntelliJ IDEA from below source

click here to download

3.Unpack the idea-8.1.3.tar.gz with tar xfz

admin@smartproteam~$ tax xfz idea-8.1.3.tar.gz

after extracting rename the file to idea-8 to make it simple

4.now copy idea-8 file to /usr/lib/

admin@smartproteam~$ sudo idea-8 -R /usr/lib

Now you need to configure the JDK_HOME and path for IDEA

5first you need to edit /etc/environment by running below command

admin@smartproteam~$ sudo gedit /etc/environment

add below lines to /etc/environment

export JDK_HOME=”/usr/lib/jvm/java-6-sun/”

add /usr/lib/idea-8/bin to this path

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/idea-8/bin”

after setting above once logout and login

6.now run below idea.sh to launch the IntelliJ IDEA like below

admin@smartproteam~$ idea.sh

now you can launch the Intellij

Source

Monday, February 28, 2011

How to Install Apache, PHP, MySQL, and PHPMyAdmin on Ubuntu

Install Apache:
sudo apt-get install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils

Install PHP:
sudo apt-get install php5 libapache2-mod-php5 php5-common php5-gd php5-mysql php5-imap php5-cli php5-cgi php-pear php-auth

Install MySQL:
sudo apt-get install mysql-server mysql-client
here you will be ask to input root password for the mysql

Install PhpMyAdmin:
sudo apt-get install phpmyadmin
here you will be asked some question to configure the phpmyadmin, just go through the wizard after it finish installed.

To set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf.

Include /etc/phpmyadmin/apache.conf
(It might be no need to add this line any more - http://manoftoday.wikidot.com/ubuntu#toc26)

Now your server is ready. Before you test please make sure to restart the server:

/etc/init.d/mysql restart
/etc/init.d/apache2 restart

then point your browser to
http://localhost/phpmyadmin

Enable mod_rewrite
sudo a2enmod rewrite

Install cURL
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

Enable modules

sudo a2enmod cache & a2enmod disk_cache & a2enmod proxy & a2enmod proxy_http & a2enmod headers & a2enmod expires


Other tools

sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl


[SOLVED] “Could not reliably determine the server’s fully qualified domain name, using … for ServerName”

You might probably faced the same following error while you were restarting the Apache server on Ubuntu.

in either httpd.conf or apache2.conf in /etc/apache2 and restart apache the notice will disappear. 

sudo gedit /etc/apache2/httpd.conf
sudo gedit /etc/apache2/apache2.conf

By default httpd.conf file will be blank. Now, simply add the following line to the file.

ServerName localhost

Save the file and exit from gEdit.

Finally restart the server.
sudo /etc/init.d/apache2 restart

(http://russenreaktor.wordpress.com/2010/04/17/solved-%E2%80%9Ccould-not-reliably-determine-the-server%E2%80%99s-fully-qualified-domain-name-using-for-servername%E2%80%9D/)



More Help:
https://help.ubuntu.com/community/phpMyAdmin

https://help.ubuntu.com/community/ApacheMySQLPHP

Source:
http://www.ivankristianto.com/os/ubuntu/howto-install-apache-php-mysql-and-phpmyadmin-on-ubuntu/1027/

Friday, February 11, 2011

Set-up ClamAV on Ubuntu

sudo apt-get install clamav

sudo freshclam


which will install the ClamAV antivirus program and download its database of virus signatures. (In the future, Ubuntu will automatically run freshclam to update the database every day.)

Now let's suppose you're exporting a directory called /home/me/publicdata to your Windows users. You can scan that directory by typing

sudo clamscan -r /home/me/publicdata

and see what it reports. You can tell clamscan to remove infected files automatically (type "man clamscan" for details), but I suggest the first time out you look at the clamscan report and determine for yourself what files look suspicious.

After you've cleaned everything up, you'll probably want to run clamscan every day, or if your users are out of control, every hour. Here's a simple script that runs clamscan and mails a report to the address in NOTIFY. Replace "me@example.com" with the address to which you want reports to be sent, and "/home/me/publicdata" with the directory you want scanned (clamscan will automatically examine all the subdirectories of this directory as well):

#!/bin/sh
TARGET=/home/me/publicdata
NOTIFY=me@example.com

clamscan -r $TARGET 2>&1 | mail -s 'Clamscan report' $NOTIFY

(You may not have the "mail" program installed. Run "sudo apt-get install bsd-mailx" if it's missing.)

Use an editor to create that file in /usr/local/sbin. I recommend the nano editor because it has help menus. At the prompt in a Terminal, type

sudo nano /usr/local/sbin/virusscan.sh

then copy the code above into that file. Hold down the Ctrl key and type S; say "yes" to save the file, then hold down Ctrl and type X to exit nano.

Only two more tasks await. First, you must make the script executable by running the command:

sudo chmod u+x,go-x /usr/local/sbin/virusscan.sh

This will allow the "root" (administrative) user, and only the root user, to execute this script. Finally, to make this script run every hour, you should create a "symbolic link" to the file (rather like a Windows "shortcut") in the directory /etc/cron.hourly like this:

sudo cd /etc/cron.hourly
sudo ln -s /usr/local/sbin/virusscan.sh

This will run the script once each hour. (You can limit it to once a day by replacing "cron.hourly" with "cron.daily" above.)


Source : http://ubuntuforums.org/showthread.php?t=1580738

Clamscan Option : http://linux.die.net/man/1/clamscan

Howto Install Clam AntiVirus with GTK frontend GUI : http://www.ubuntugeek.com/howto-install-clam-antivirus-with-gtk-frontend-gui.html

Thursday, February 10, 2011

How to check port activity and manage

netstat

netstat -e -e

netstat -pant

1- Find what application/process is using the pro, type:

sudo netstat -lpn |grep :8080

and press Enter.

You will get an output similar to this one

tcp6 0 0 :::8080 :::* LISTEN 6782/java

2- I have got the process Id, which is 6782, now this is the process that is using port 8080.

3- Kill the process, type:kill 6782

kill 6782

and now port 8080 is free.