msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

02 Feb 2012 Recursively symlinking files

Posted by

This is a short script I use to symlink all my JPG image files on my file server to a flat folder accessible to my DLNA enabled devices.
My files are organized in year folders and under each year there are month folders:

-2011
--2011-01
--2011-02
--2011-03
...
-2012
--2012-01

I avoid duplicate symlinks by using file names like 20110102-1234_DSC…JPG or YYYYMMDD-HHMM_OriginalFileName.JPG

The script looks like this

#!/bin/bash 

SRC="/media/Images"
DEST="/media/SymlinkTarget"

# Create a symlink under $DEST for each JPG file under $SRC
find $SRC -type f | grep -i jpg | while read PATHNAME; do
        NEW="$DEST";
        echo "$NEW";
        ln -s "$PATHNAME" "$NEW";
done

Tags: , ,

Comments are closed.