Archive for the ‘cygwin’ Category

Recursively compare content of two directories

August 31, 2017 Leave a comment

Command line

This requires the diff and vim packages.

diff --recursive /dir/ect/ory1 /dir/ect/ory2 > 1_vs_2.diff
vimdiff 1_vs_2.diff

Potentially useful diff options:



Install Intellij CE.

Then either Run IntelliJ Diff from the command-line.

Or from within a running Intellij window:

  • Open a common parent directory as a project
  • Select the two directories to compare
  • Right-click – Compare Directories


I often see the GPL-licensed WinMerge tool recommended, But it works only on Windows, last release was 2013 and navigation into sub-directories and file diffs is a bit clunkier than in Intellij.


Determine which Tomcat version is running

August 6, 2016 7 comments

Determine process id

First we determine the process id(s) of the running Tomcat instance(s).

We can grep the running process list for ‘catalina.home’:

pgrep -f 'catalina.home'

This might yield more than one pid.

Or we can search by port (8080 is the default, adjust if necessary). The following commands will likely require root privileges:

lsof -t -i :8080

Alternatively, for example if lsof is not installed:

fuser 8080/tcp

Or yet another way, using netstat (or its “ss” replacement):

netstat -nlp | grep 8080
ss -nlp | grep 8080

Determine catalina.home

For the process id(s) determined above, we look at process details:

ps -o pid,uid,cmd -p [pidlist] | cat

For each specified pid, this shows the uid (system user) and the full command line of the process.

Typically the command line will contain something like “-Dcatalina.home=[path]” and that path is the catalina.home system property of the Java process.

Alternatively – with Java 7 and later – we can use the JDK command “jcmd” to query the JVM process for its system properties:

sudo -u [uid] jcmd [pid] VM.system_properties \
   | grep '^catalina.home' \
   | cut -f2 -d'='

Determine version

Now we can finally determine which Tomcat version is installed under the catalina.home path:

[catalina.home]/bin/ version \
   | grep '^Server number:'

Note: Please replace [catalina.home] with the path you determined above.

The final output should be something like this:

Server number:

Compare two Tomcat installations using rsync

May 5, 2016 Leave a comment

Lets assume you manage multiple servers that host Java web applications using the Tomcat web server.

To quickly compare the Tomcat installations on host1 and host2, we can use the “dry-run” mode of the rsync command.

In the following example, we assume that you have ssh access to both of your Tomcat hosts, the installations are in /opt/tomcat and the “tomcat” system user has read access to all relevant files and directories of the installation:

ssh tomcat@host1
rsync --archive --checksum --dry-run --verbose --delete \
      --exclude temp --exclude work --exclude logs --exclude webapps \
      /opt/tomcat/ tomcat@host2:/opt/tomcat/

This will list

  • All files that differ in checksum
  • All files that only exist on host2 (look for ‘deleting [filename]’)

Run the same commands with host1 and host2 switched, to also see the files that only exist on host1.

We excluded the temp, work and logs directories because they are variable in nature.
We also excluded the webapps directory because we only wanted to compare the base installation.

Categories: bash, coding, cygwin, debian, linux, mac os

Fix Eclipse installation after Cygwin unzip

August 5, 2015 Leave a comment

I used Cygwin’s unzip on Windows 7 to unpack freshly downloaded Eclipse zip packages. When trying to start eclipse.exe, I was getting weird error messages:

For Luna (4.4):


For Mars (4.5):


It turned out that after unzipping, the executable permission was not set on ‘exe’ and ‘dll’ files, so I had to fix it like this:

find eclipse \( -name '*.dll' -or -name '*.exe' \) -exec chmod +x {} \;

Categories: bash, coding, cygwin, dev-tools, eclipse

Human readable timestamp for filenames

November 13, 2014 Leave a comment

I use this bash alias (should work in Linux, Cygwin, probably MacOS, maybe other Unixes):

alias timestamp="date --rfc-3339=ns | tr ' '  '_'"

Then use it like this for example to archive a file:

mv somefile somefile_$(timestamp)

You should see something like

`somefile' -> `somefile_2014-11-13_11:45:46.980175800-04:00'

If you don’t like colons in file names, change tr ' ' to tr ' :'.

Start script for stand-alone Java process

September 26, 2014 Leave a comment

Directory structure

  • lib
    • some.jar
    • another.jar
  • config
    • dev
    • uat


# environment (typically 'dev', 'uat' or 'prod') 

# absolute path to java home ( >= 1.7 ) 
# such that $java_home/bin/java exists 

# add any additional environment setup here:


# script should exit if any command fails 
set -e 

function envfail() { 
  echo $1; 
  echo "Please adjust $setenv_script and retry ..." 
  exit 1 
function check_not_empty() { 
  if [ -z "$1" ]; then 
    envfail "Variable '$2' is unset or empty." 

script=$(readlink -f "$0") 
if [[ "$script" =~ .*[[:space:]].* ]]; then 
  echo "Script path contains spaces: $script" 
  echo "Please fix and retry ..." 
  exit 1 

# ok, now we know $script contains no spaces so 
# we don't need quoting acrobatics from here on 

dir=$(dirname $script) 
parent=$(dirname $dir) 

if [ ! -e $setenv_script ]; then 
  echo "$setenv_script not found" 
  cp $dir/ $setenv_script 
  envfail "Created a default $setenv_script for you." 
setenv_script_file=$(readlink -f $setenv_script) 
if [ -r $setenv_script_file ]; then 
  echo "Sourcing $setenv_script" 
  source $setenv_script 
  envfail "Cannot read $setenv_script" 

check_not_empty "$env" 'env' 
config_env=$(readlink -f "$dir/config/$env") 
if [[ ! -r "$config_env" || ! -d "$config_env" ]]; then 
  envfail "Invalid env=$env : Cannot read directory $config_env" 

check_not_empty "$java_home" 'java_home' 
if [ ! -e "$java" ]; then 
  envfail "$java is not an executable file" 
java_version=$("$java" -version 2>&1 \
               | head -n 1 | cut -d'"' -f2 | cut -d'.' -f2) 
if [ $java_version -lt "7" ]; then 
  envfail "Java 1.7 or higher is required." 

# turn on bash debug output for the following lines 
set -x 

cd $dir 
mkdir -p "../log" 

nohup \ 
"$java" -cp "$config_env:lib/*" \
        net.doepner.example.Main \ 
        > "../log/example_stdout.log" 2>&1 & 
Categories: bash, coding, cygwin, java, linux, mac os

Get java version string via shell commands

July 27, 2014 Leave a comment

Determine the pure java version string from any Unix/Linux shell (including Cygwin):

java -version 2>&1 | head -n 1 | cut -d'"' -f2

This requires only the very commonly available and lightweight “head” and “cut” commands.

I originally found the one-liner on stackoverflow.
Thanks to the friendly folks who shared it.

The above gets the version from the java command on the PATH.
For other java binaries on your system, use the full path, like:

/full/path/to/some/java -version 2>&1 | head -n 1 | cut -d'"' -f2

To get only the major version part (e.g. 7 for Java 1.7.x), use this:

java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f2 

Example: Ensure Java 7 or higher:


version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f2)
if [ $version -lt "7" ]; then
  echo "Java 1.7 or higher is required."
  exit 1
Categories: bash, coding, cygwin, debian, java, linux, mac os Tags: , ,