OwnCloud Camera Import Sort Script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
BASE_DIR=/var/www/owncloud.heimdaheim.de/data/christian/files/Camera-Import
SORT_DIR=/var/www/owncloud.heimdaheim.de/data/christian/files/Camera-Sorted

find "$BASE_DIR" -type f -name "*" | while IFS= read -r file; do
  year="$(date -d "$(stat -c %y "$file")" +%Y)"
  month="$(date -d "$(stat -c %y "$file")" +%b)"
  filestamp="$(date -d "$(stat -c %y "$file")" +%Y%m%d)"
  
  [[ ! -d "$SORT_DIR/$year/$month" ]] && mkdir -p "$SORT_DIR/$year/$month"
  
  mv "$file" "$SORT_DIR/$year/$month/${filestamp}_${file##*/}"
done

Description

This Bash script automatically sorts camera uploads from OwnCloud into a year/month directory structure. Files are organized based on their modification date and prefixed with a timestamp in the filename.

How it works

  1. Searches the Camera-Import directory for all files
  2. Extracts the year and month based on each file’s modification date
  3. Creates target directories (Year/Month) if they don’t exist
  4. Moves files to the appropriate folders with a YYYYMMDD_ prefix

Usage

Simply run the script to organize all camera imports into a chronological folder structure.