Linux: Auto-mounting USB camera memory

I have 2 cameras. One takes Flash cards, the other takes SD cards. If my Sony still worked, I’d also add memory sticks to that list.
I’ve got a routine, a workflow, for copying photos off camera media but it’s slightly more complicated with multiple memory types!
Kevin Lyda kindly mailed me a script he had for auto-mounting his camera and copying the files off. It uses the usb hotplug program to do that but I couldn’t get it to work with my card reader so I wrote the following script. Bits of it are from Kevin’s scipt, so thanks!
I insert my camera media, and run “” and it find the Flash card and copies all files off it into a directory with today’s date!

Make sure you have your media mount points setup in /etc/fstab. Here’s what mine looks like:

/dev/sdb1 /mnt/cfcard vfat users,noauto,rw,uid=1000 0 0
/dev/sdd1 /mnt/sdcard vfat users,noauto,rw,uid=1000 0 0

Copy and paste this into a file and save it to /usr/local/bin/ and make it executable (chmod 755 /usr/local/bin/


export YEAR=`date +%Y`
export TODAY=`date +%Y-%m-%d`
export DIR=/home/donncha/Photos/$YEAR/$TODAY/
mount /mnt/cfcard/ 2> /dev/null
if [ -d /mnt/cfcard/dcim/ ]; then
    mkdir -p $DIR
    find /mnt/cfcard/dcim -type f -print0 | xargs -0i mv -vi '{}' $DIR
    umount /mnt/cfcard/
    df -h
mount /mnt/sdcard/ 2> /dev/null
if [ -d /mnt/sdcard/dcim/ ]; then
    mkdir -p $DIR
    find /mnt/sdcard/dcim -type f -print0 | xargs -0i mv -vi '{}' $DIR
    umount /mnt/sdcard/
    df -h

One thought on “Linux: Auto-mounting USB camera memory

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.