Category Archives: Tips and Tricks

Detecting Java Processes listening on local ports

We can use the jps command that is part of JDK to find out which Java processes are running in the current user’s session. We can further find out which network ports have been opened by a particular java process.

Use the follwing command to list all java processes:
jps -l

If you want more details about a process you can execute the following command:
jps -v | findstr <process id>

The following variant of netstat command lists all the listening as well as established socket connection in a system:
netstat -ano

This command can be further used to find out what sockets are opened by a specific process
netstat -ano | findstr <process id>

See hidden files in Mac OS Finder

I like to see all the files in the project folder where I am working. So it is inconvenient not being able to see “.gitignore” and “.git” inside the folder where I have git repository. On a brief lookup of the internet I found this article which proposes two approach of making hidden files visible in finder.

Approach #1: Using Terminal

To show hidden files
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

To turn off showing of hidden files
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

Approach #2: Using an App
Funter is a small app which allows the user to toggle the hidden file visibility on and off at the click of a button which is quite convenient.

What I used?
I preferred the terminal approach as I am fairly comfortable with it and I didn’t want to add a new application into my mac’s start-up and menu bar.

How to find Linux distribution and kernel version

In order find out what version of Linux you are running you can execute either of the following commands:

  • cat /etc/*-release
  • lsb_release -a
  • cat /proc/version
  • dmesg | head -1

To find out the kernel version of Linux you can execute either of the following commands:

  • uname -a
  • uname -mrs

Disclaimer: These commands worked for me on Debian Linux.

Update for Oracle Linux

The following commands gave accurate information about OS and release numbers on Oracle Linux.

rpm -qf /etc/redhat-release

oraclelinux-release-6Server-8.0.3.x86_64
cat /etc/issue.net | head -1

Oracle Linux Server release 6.8

 

Multi tabbed windows explorer

In this world of multi-tabbed browsing I find it inconvenient that Windows Explorer has no multi tabbed support. I did some search and found out Clover. I downloaded and installed this tool and voila my Windows Explorer has got tabs. The tool itself is simple and integrates seamlessly with Windows Explorer in Windows 8. I have not had time to check it on my Windows 7 laptop, maybe sometime soon I will post an update.

Finding unread email in Android GMail Client

Recently I noticed that my GMail inbox showed ‘0’ unread emails but my Android phone showed ‘1’ unread email persistently. I found the following trick which solved this problem. On my handset I clicked on ‘Search’ option and then typed the following in the search bar:

is:unread in:inbox

This allowed me to show only unread email in my Android Gmail client. Out Popped a one and half month old email which was still unread. All I had to do was open that email and the issue was gone.

What is not clear to me is how the GMail website showed 0 unread email while the Android client showed 1 unread email simultaneously for weeks at stretch. Perhaps the Android GMail client does a better job at keeping track if you missed reading a particular email a while back.

Open Command Window Here in Windows 7

Being a hard core java programmer the Windows console is only one step away from me. In Windows 7 I use a nifty inbuilt feature which allows me to open a command window and switch to a given directory in a single step.

  • Using My Computer / Windows Explorer navigate to the relevant folder.
  • Press Shift and do a Right Click either on the folder name.
  • You will get a popup menu with the option “Open Command Window Here”.
  • Clicking on this option will open the console / terminal window with this folder as the current directory.
  • You can Right Click on an empty area as well to open the console/terminal for the current folder.

This facility is a time saver and I really like using it every now and then.

Windows 7 File Sharing Client Quirk

If you are like me you might have multiple user accounts on the target windows box and you might want to switch the network credentials used to login by the Windows. One thing which I have found extremely annoying is the tendency of Windows Explorer to remember your last credential even when you have kept the “remember credentials” checkbox unchecked. I am not talking about credentials which you ask Windows to “remember” but about credentials which you don’t want Windows to remember so that if I closed explorer and re-opened the explorer and tried to access a remote computer’s file share I should be asked for the credentials again. I don’t know if this is a Windows 7 specific behavior or not but I am facing this issue on Windows 7. This logon is basically cached for your convenience. But what if you don’t want your credentials to be cached, what if you want to switch your credentials rapidly. This might sound stupid to some but it is helpful once in a while.

Well I found a workaround which is clunky but works great. Open a command prompt in administrator mode and execute the following command.

net use \\your_remote_computer\share /delete

This command basically terminates the connection to your remote computer if it’s not already terminated. If you want to terminate all your connections then execute the following command instead of the above command.

net use * /delete

The above command ensures that all connections to any remote computers are terminated. This command might ask you for confirmation in the command prompt. Answer “yes” for all connections. Now follow up with the following command:

klist purge

This command basically terminates the Kerberos Ticket for the credential you had for your remote computer if it has not already been done.  Please note you need to ensure that the connection to the remote computer has been terminated and then purge the outdated kerberos tickets for closed connections so you need to execute the 2 commands in sequence. This will ideally solve this little problem.

 

Locale issue in Linux VPS Box

In case of a new Linux VPS box it is possible that you might encounter an error like this:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = “UTF-8”,
LANG = “en_US.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).

To solve this error the following approach worked for me on my Debian box. Execute the following command

sudo vi /etc/ssh/sshd_config

In this file comment the following line. This line basically allows the client OS to pass it’s environment parameters to the remote server which can cause issues.

AcceptEnv LANG LC_*

Save the file and reboot the VPS box. After rebooting this error should not ideally come. If you are still getting this error then it is possible that you don’t have the locale installed. The following command might help you in resolving this problem.

sudo locale-gen
sudo dpkg-reconfigure locales

 

Prioritizing Network Connection in Windows

Windows somehow gives LAN cable connection priority for connecting to internet. This was a mystery which has boggled me for quite some time. Recently I landed in a scenario where on my laptop I had a LAN cable connection as well as a WiFi connection. Now in this situation both Ethernet and WiFi adapter have got internet access via different ISP and the gateway for both are different. Now I wanted my FTP client to download stuffs via my LAN cable and I wanted my Dropbox client to upload files via my WiFi connection. After spending some time on internet I found out that the only solution that guarantees result is to take control over the metrics of the network adapters. If the metrics of WiFi is made lower than the metrics of Ethernet then Windows OS routes all internet traffic via WiFi. After changing the metrics I checked and confirmed that my Browser and Dropbox applications were using WiFi instead of Ethernet. This seems to be working reliably for now. I performed the following steps:

  1. Open command prompt (type cmd.exe in Start Menu in Win 7 or in Run dialog in Win XP).
  2. Type ncpa.cpl (This will open the network connections windows)
  3. Right click on your Wireless Network Connection adapter (WiFi).
  4. Click on “Properties” in the popup. This will open the properties dialog.
  5. In the properties dialog choose “Internet Protocol Version 4 (TCP/IPv4)”.
  6. Click on “Properties” button. This will open the “Internet Protocol Version 4 (TCP/IPv4) Properties”.
  7. Click on the “Advanced” button. This will open the “Advanced TCP/IP Settings”.
  8. In this dialog uncheck the “Automatic Metric” checkbox.
  9. Type ‘1’ without quotes in the “Interface metric” text field.
  10. Click on OK in this dialog and the underlying dialog to save your changes. Click on “Close” in the properties dialog to conclude this task.
  11. Now in the Network Connections window select your “Local Area Connection” (Ethernet Adapter).
  12. Repeat steps 4 through 10 with the only difference that in step 9 type ‘2’ instead of ‘1’.
  13. That’s it you are done.

The idea is that if you provide a lower metrics to your WiFi and a higher metrics to your LAN/Ethernet adapter then Windows OS will always use your WiFi connection for all Internet traffic. This worked well for me.