Get Thread and Heap dump – Java


Thread and Heap dumps are useful for debugging any Java programme.

To get thread dump:

By using jstack command we can get thread dump of a Java process.


$ jstack PID

where PID is Java process id for which we want to get thread dump.

To get heap dump:

By using jmap command we can get heap dump of a Java process.


$ jmap -heap PID

where PID is Java process id for which we want to get heap dump.

ping ip with port


Ports are a concept of UDP and TCP. Ping messages are technically referred to as ICMP Echo Request and ICMP Echo Reply which are part of ICMP. ICMP, TCP, and UDP are “siblings”; they are not based on each other, but are three separate protocols that run on top of IP.

Therefore you can not ping a port. What you can do, is use a port scanner like nmap and check if ip/host and port are accessible.

$ nmap -p 80


Starting Nmap 6.40 ( ) at 2015-12-02 14:38 IST
Nmap scan report for (
Host is up (0.085s latency).
Other addresses for (not scanned):
rDNS record for
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 0.64 seconds

You can also use telnet 80

Linux – Ping multiple hosts using fping


fping is a ping like program which uses the Internet Control Message Protocol (ICMP) echo request to determine if a host is up.

With fping we can ping multiple hosts at a time. Use following command to ping multiple hosts:

$ fping -f IPsFiles.txt 

where in IPsFiles.txt I have multiple hots.

Below are some other examples of fping:

To ping a host/IP:

$ fping

Output: is alive

$ fping

Output: is unreachable

To ping range of IP’s:

$ fping -g

To list only unreachable hosts/IP’s

$ fping -q -u -f IPsFiles.txt

where -q is for Quiet mode and -u is to list only unreachable targets.

To list only reachable hots/IP’s

$ fping -q -a -f IPsFiles.txt

where -a is to list only alive hots.

iptables allow port for ip


To allow only an ip to access a port use following iptables rule

iptables -I INPUT -p tcp -m tcp -s --dport 8080 -j ACCEPT

Above iptables rule will allow only to access port 8080 and reject all other ip addresses.

Similarly we can give any other ip address and port combination.

Crontab every 30 seconds


To run a cron every 30 seconds check following example:

* * * * * /path/to/your/script arg1 arg2
* * * * * (sleep 30; /path/to/your/script arg1 arg2)

In above example both commands will start at 0th second of every minute, but the second command will sleep for 30 seconds and then start.

Vim – highlight search keyword


By default search keyword won’t be highlighted in vim with Ubuntu OS.

To highlight search keyword we need to set hlsearch flag in vimrc.

Open /etc/vim/vimrc with sudo and append following line in it:

set hlsearch

After that save & exit from vimrc file. This will enable search keyword highlight across all vim sessions.

If you want to enable highlighting only for current session run following command in vim after opening a file:

:set hlsearch

Username and password with wget/curl


To download a url with basic authentication we need to pass username & password.

To acheive this functionality with wget or curl observer following examples:

With curl:

$ curl -u 'username:password' ''

With wget:

$ wget --user='username' --password='password' ''

Wget with cookie:

Login to server & save cookie to a file:
$ wget --save-cookies cookiesFile.txt --post-data 'user=username&password=password'

Download a page by using saved cookie file:
$ wget --load-cookies cookiesFile.txt -p

ssh disable warning messages – Linux/Ubuntu

To disable ssh warning message we need to add LogLevel to quiet in $HOME/.ssh/config file.


We can also diable warning messages with ssh command as shown below:

$ ssh -o LogLevel=quiet

With following example we can also disable Host Key Checking, set known hosts file to null and disable logging:

$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet

ssh remove offending key – Linux/Ubuntu


ssh-keygen command is used to remove offending key entries from .ssh/known_hosts

Syntax to remove offending key of a host:

$ ssh-keygen -R hostName/IP_Address

Example 1:

$ ssh-keygen -R

Above example will remove ssh key associated with hostname

Example 2:

$ ssh-keygen -R

This example will remove ssh key associated with IP Address