Category Archives: Linux

Enabling HSTS in Apache 2.4

After securing one of my servers with Let’s Encrypt, I was a bit disappointed that my website only got an A result on the Qualys SSL Server Test. Why did I not get the much sought-after A+?

Browsing the Protocol Details of the report, I discovered that my website was lacking Strict Transport Security (HSTS) support. This is how I enabled it on my Apache 2.4 web server running on Debian 8… Continue reading Enabling HSTS in Apache 2.4

Moving files to subdirectories based on date in the filename

My camera produces JPG files that have date and time information in the file name. I want to  move the files to new subdirectories per year, month and day.
IMG_20150723_233831.jpg -> 2015/07/23/IMG_20150723_233831.jpg
IMG_20151001_174215.jpg -> 2015/10/01/IMG_20151001_174215.jpg

I wrote this small perl script to perform this task:

# Move files to new subdirectories based on file name.
# CC BY SA 2015, Lieven Blancke
# my camera produces JPG files named IMG_yyyymmdd_nnnnnn.jpg
# I want to move these files to subdirectory per year, month and day
# IMG_20150723_233831.jpg -> 2015/07/23/IMG_20150723_233831.jpg
# IMG_20151001_174215.jpg -> 2015/10/01/IMG_20151001_174215.jpg
use strict;
use warnings;
use File::Copy;
use File::Path 'make_path';

my $directory = './';

opendir (DIR, $directory) or die $!;

while(my $file = readdir (DIR)) {
	# ignore files beginning with a period
        next if ($file =~ m/^\./);
	# only files, no directories
	next unless (-f "$file");
	# only process files like IMG_yyyymmdd_nnnnnn.jpg
	if ($file =~ /^IMG_([0-9]{4})([0-9]{2})([0-9]{2})_([0-9]{6})\.jpg$/) {
		print "$file -> $1/$2/$3/$file\n";
		# create the directory $1, $1/$2 and $1/$2/$3 in one go
		# move the file to the directory
		move($file,"$1/$2/$3/$file") or die "Could not move file $1 to directory /$2/$3: $!";


Extracting audio from a YouTube video using avconv

You can download YouTube videos with the NetVideoHunter Firefox add-on. After installing the add-on, you can download a YouTube video by clicking the icon.


By default the add-on downloads the best available quality from YouTube, that is very convenient.

The downloaded file has an mp4 extension.  Using the libav command line tool avconv, you can extract the audio without transcoding. This way the process is very fast and the audio quality remains the same:

avconv -i testvideo.mp4 -codec copy -vn testaudio.m4a

The -codec copy option makes sure the audio is extracted without conversion an the -vn option excludes the video being written to the output file.

To install avconv on Debian:

sudo apt-get install libav-tools