Category Archives: Linux

linux

exifsort.pl – Sort digital images by EXIF date.


I use 2 digital cameras, and my phone, to take pictures nearly every day. I came accross a perl script written by Lars Strand. This copied photos from CAM0001.JPG to a date formatted file such as 20070113.0900.JPG.

I decided to take this as a base, and change it into something that suited my own needs.

The script will take directories on the command-line and copy any pictures found to a target directory set within the script. It then creates a file and directory structure based on the EXIF time/date found in the JPEG.

For example

/source/CAM0001.JPG

now becomes

/target/2007/11.nov/20070113.0900.jpg

making the files easy to find and splitting them into months.

The script produces an output such as,

ExifSort v1.0 - http://www.nooblet.org/exifsort/

o Processing folder, /mnt/storage/Photos/100DSCIM/
o Processing folder, /mnt/storage/Photos/100CASIO/
CIMG0553.JPG -> 20071111_145714.jpg
CIMG0554.JPG -> 20071111_153500.jpg
CIMG0555.JPG -> 20071111_153529.jpg
CIMG0556.JPG -> 20071111_153614.jpg
CIMG0557.JPG -> 20071111_155707.jpg
CIMG0564.JPG -> 20071111_181839.jpg
CIMG0567.JPG -> 20071111_182038.jpg
CIMG0569.JPG -> 20071111_182659.jpg
CIMG0574.JPG -> 20071111_215006.jpg
CIMG0575.JPG -> 20071112_120508.jpg
CIMG0580.JPG -> 20071112_120723.jpg
CIMG0582.JPG -> 20071112_182803.jpg
o Processing complete.
12 files copied.
- 101 files the same.

The script checks modified dates and file sizes, and will compare the md5 checksum if it still isn’t sure, to know if it has already copied an existing file.

The photos folder in my family photo gallery is a direct result of this exif sorting script.

Requirements:

Download
  exifsort.pl (5.2 KiB, 4,247 hits)

Postfix Transport Maps – Diverting Mail Traffic


If like me, you host your own mail server on your broadband then you may of come accross this problem. Some ISP’s refuse to accept mail from dynamic IP ranges, and so they should! E-mail aware worms and viruses are used all over the world to send us spam, and the majority of them are on consumer PC’s hosted on dynamic IP ranges.

Now, if you don’t have a static IP, and you want to send mail to a Gmail address your mail will be rejected. Using postfix as your MTA, you can work around this.

Most ISP’s offer an SMTP relay server, now you may not want to use this all the time, so transport maps can send only mail for gmail addresses to your smtp relay, and the rest can go direct.

Find out what your ISP’s SMTP server address is, usually smtp.yourisp.com. Create a file named transport in /etc/postfix and add the following text,

gmail.com smtp:smtp.yourisp.com:25
googlemail.com smtp:smtp.yourisp.com:25

Remember to swap “smtp.yourisp.com” for the address of your ISP’s smtp relay server.

Now we need to compile this file using the postmap command,

postmap /etc/postfix/transport

Edit /etc/postfix/main.cf and add this line at the bottom,

transport_maps = hash:/etc/postfix/transport

Restart postfix and you should find all mail addressed to @gmail.com or @googlemail.com will be redirected to your smtp relay.

Changing Colour of Files/Directories in Linux ‘ls’


A default colour set is available in Debian for many file types. A quick look at ~/.bashrc shows that we can uncomment a few lines to enable the colouring of directories and files by extension.

The relevant lines in my ~/.bashrc are,

export LS_OPTIONS='--color=auto'
eval "dircolors"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'

The command dircolors outputs the line needed to put the colour information into your environment space. A man dircolor revealed the ability to edit its output.

Using dircolors --print-database you can get the list of colours in an editable form, so if we pipe that to a file,

dircolors --print-database > /etc/dircolors

We can edit this file name and add the colors we want. The file has some explanations as to what the numbers represent.

I added a couple of lines so that .7z and .rar files appear the same as the other compressed archives did.

.tar 01;31 # archives or compressed (bright red)
.gz 01;31
.bz2 01;31
.deb 01;31
.rpm 01;31
.rar 01;31 # added
.7z 01;31 # added

Following this change we need to edit the ~/.bashrc file again to use this new configuration file rather than the default in-built database. Just edit the line beginning with “eval” so it reads,

eval "dircolors /etc/dircolors"

Now you’ll find the new file extensions coloured how you want them. 🙂