Using GIMP to draw a rectangle

GIMP is not your typical program for drawing, but is is the only thing related to graphics that is installed on my linux. So I have this screenshot and I want to draw a red rectangle around the part that needs to be clicked. This is how:

  1. Open your graphic file with GIMP.
  2. Use the "Rectangle Select Tool" and mark the place where you want your rectangle to be.
  3. Select the color you want to draw the rectangle in as foreground color (in my case that would be red).
  4. In the menu "Edit" choose "Stroke selection".
  5. In the dialogue that comes up, choose "Stroke line" with "solid colour" (it will take the current foreground color), you can adjust the width and if you open up "Line style" you can do more things (e.g., rounded edges).
  6. Click "Stroke" and voila!

Executing a command on a remote server

This is probably a very old hat for Linux-savy people. You can use ssh to execute commands on a remote server, just pass them on as an additional argument:

ssh "cd bla ; ls ; python "

I use double quotes (“) istead of single quotes (‘) to interpret variables. Different commands are separated with semicolon (;). You can use any command you like, but for some reason when I call some GUI I don’t get the output on the command line until the window is closed.

Open SSH folder in Dolphin using a SSH-key

Dolphin allows you to connect to folders on other machines per SSH, but there is no option to specify a key file. But you can add the key to your general SSH configuration (with the added benefit that you also won’t have to specify the keyfile anywhere else, no more -i on the command line!). This is how it works:

  1. Locate your private key file, say it’s ~/.ssh/myidentity_rsa.
  2. Open or create the file ~/.ssh/config and add the lines
      IdentityFile ~/.ssh/myidentity_rsa
  3. Type fish:// into the location bar.
  4. Now it should ask for the passphrase to your key.


Get folder/filename from a path

Get folder name, filename, file extension from a path:

# File name: Strip from start longest match of [*/]

# Folder: Substring from 0 to start of filename

# File prefix: Strip from end longest match of [dot plus at least one non-dot char]

# File extension: Strip from start shortest match of [at least one non-dot char plus dot]

Replace newlines with sed

Sed is a commandline linux tool to replace text in a file or input stream. Typically sed works line-oriented, i.e., a line is read, the expression applied, then the next line is read. Say we have a file where one line is one word. We want to reconstruct the sentence. How to replace all linebreaks in the file with a space? Simple:

sed "{:q;N;s/\n/ /g;t q}" 

The regular expression ‘s/\n/ /’ says substitute linebreaks (\n) by a space. ‘g’ says apply this globally. ‘N’ says append the next line to what is processed. Using only ‘N’ would replace linebreaks in every second line. The rest of the thing is a trick to join all lines together. We define the label q (‘:q;’), then we say that in case that there was a sucessfull substitution, go to label q (‘t q’).

Now we have all words in one line. Across sentences! Sentences are separed by an empty line. So easy – replace linebreaks by spaces, replace two adjacent spaces by a linebreak. Gives you one sentence per line, words separated by spaces. Voila:

cat  | sed "{:q;N;s/\n/ /g;t q}" | sed "{s/  /\n/g}"

Which process has an open handle on my file x (fuser, lsof or Process Explorer)?

Here’s how to find out if a file is locked because of another process that still has an open file handle.

On Linux/Unix just use: fuser or lsof

lsof | grep
fuser -v

On Windows the Sysinternals Process Explorer is a great answer to this (and many other questions):

Just Ctrl+F and enter the name or part of it and search