Sort file into subdirectories structures by year and month
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. ...