Remove duplicate lines while comparing two files

I’ve been quite busy this whole day with a partially complete database dump and wanted to prepare for tomorrow with some ninja bash voodoo shizzle. I’m doing a braindump here because I know I’ll have forgotten this when I wake up tomorrow :-)

The command stated below was the first working example I’ve gotten together, please let me know if you know a neater / better solution!

The situation:

I’ve got two files. The first file contains lines which need to be deleted from the second line (if they exist there) Continue reading “Remove duplicate lines while comparing two files”


Remove host from SSH KnownHosts file without seeing the hostname

This post is mostly a bookmark for myself. I’ve been using search engines way too often to find this command..

The command to remove a host from a knownhosts file without seeing the actual hostname in the knownhosts file is the following:

ssh-keygen -R HOSTNAME

Continue reading “Remove host from SSH KnownHosts file without seeing the hostname”

Comparing sed stream output in linux

Sed is very very powerful, which is a good thing to be aware of.
I was looking to compare the output of a sed command to the original file before I wanted to execute the sed command directly on the file and came across this handy trick.

It works by using temporary named pipes inside the diff command.

Contents of file:


If I just want to remove the line which begins with “Four”, I can check my sed command like this:

joris@beanie ~
$ diff <(sed '/Four/d' numbers.txt) numbers.txt
> Four

Awesome possum, now I know my sed command won’t destroy anything.

Bash: Shortcuts to your favorite directories with CDPATH

This is a fairly handy trick.

I’m always logging in to different servers, which all have a different location for their logs. With this trick you can login and just type “cd logs” from anywhere.

First we will add our directory to the CDPATH variable:

joris@badattitude /data/share/my_domain
$ echo $CDPATH

joris@badattitude /data/share/my_domain
$ export CDPATH=/data/share/my_domain

joris@badattitude /data/share/my_domain
$ echo $CDPATH

Then we’ll check if it is working:

joris@badattitude ~
$ cd logs

joris@badattitude /data/share/my_domain/logs

Awesome, we’ve arrived in our logs directory straight from our homedir!

SSH Remote Execute command, multiple command and with interaction

This article shows how to execute remote commands via ssh, but you’ll send the commands from your own shell.

ssh my_server 'ls -l /home/my_home_dir'

This will result in this output:

$ ssh ae2 'ls -lha ~'
total 36K
drwxr-xr-x  2 joris joris 4.0K Jan 23 11:42 .
drwxr-xr-x. 5 root  root  4.0K Jan 23 11:41 ..
-rw-r--r--  1 joris joris   54 Jan 23 11:41 .bash_logout
-rw-r--r--  1 joris joris  507 Jan 23 11:41 .bash_profile
-rw-r--r--  1 joris joris  213 Jan 23 11:41 .bashrc
-rw-------  1 joris joris   51 Jan 23 11:42 .history
-rw-r--r--  1 joris joris  171 Jan 23 11:41 .kshrc
-rw-r--r--  1 joris joris  375 Jan 23 11:41 .profile
-rw-r--r--  1 joris joris  153 Jan 23 11:41 .vimrc

What’s even better, is that you can run multiple commands separated with a semi colon, like this:

ssh my_server 'ls -l /home/my_home_dir;whoami'

And the best trick is this one, user input with an interactive command, sending input and output back and forth!

ssh -t my_server 'vi ~/.bash_profile'

Find Java JRE location on Ubuntu Linux

Everybody knows that the java executable is located in /usr/bin/java , but what if you need the JDK / JRE location itself?

Just using “whereis” will not get you there, that will point you to the /usr/bin/java point.

joris@howlingmad: ~_011


So, let’s find out a but more about /usr/bin/java:

ls -l /usr/bin |grep java

joris@howlingmad: ~_012


Awesome, this will lead us somewhere, it’s a symlink to /etc/alternatives/java

So let’s do the same there:

ls -l /etc/alternatives/ |grep java

And we’ve hit the jackpot, among the lines here, there’s a bunch of lines pointing us to the JRE location:

joris@howlingmad: ~_013


As you can see in the screenshit, our java executable within the JRE location is:


Which means the JRE location is:





CHere Bash Here without Admin Rights – CYGWIN

I wanted to add a “Bash Here” context entry when I right click on a directory:

Screenshot - 28-2-2014 , 13_01_20

This Bash Here would open that directory in Cygwin (mintty).

My current PC is fairly regulated, so without admin rights and thus I can’t use the CHere option which I would normally use.

I just created the registry keys via regedit and that works fine.

You can use two options:

  1. Import the registry file mentioned below
  2. Create the keys yourself

1. Import the registry file

Create a file called cygwin_bash_here.reg with the following contents:

Windows Registry Editor Version 5.00



@="Bash Here"


Save the file and double click on it to import it to the registry.

2. Create the keys yourself

  1. Open the registry editor: Start – Run – “regedit”
  2. Open the following path: HKEY_CURRENT_USER\Software\Classes
  3. Create key: “Directory”
  4. Inside Directory, create key: “shell”
  5. Inside shell, create key: “bashhere”
  6. Inside bashhere double click on the standard key and insert text “Bash here” without quotes (This is the text which is displayed in the context menu.
  7. Inside bashhere, create key: “command”
  8. Inside command, double click on the standard key and insert text “C:\cygwin\bin\mintty.exe” without quotes. Important: This is the command which is run. Please change directory to your cygwin directory

Screenshot - 28-2-2014 , 13_16_02


Both options will create a context menu item which opens Cygwin at your current windows directory!