#!/bin/bash
#                       /usr/local/bin/find_images
#  http://crystalfaeries.net/posix/bin/find_images
# celeste:crystalfaery FIND_IMAGES 2017-12-11 21:39:50+00:00
# find images by decreasing size in specified directory list, or
# find images by decreasing size everywhere for /usr/local/bin/images or for cron job:
#	DAILY TASKS
#Minute	Hour	DOM	Month	DOW	Command
#40	02	 *	 *	*	/usr/local/bin/find_images		# update empty image files list

if	[ $# -ne 0 ]
then			# we have an argument
	target="$@"	# search specified list
else			# no arguments means
	target="/"	# default to searching EVERYwhere
fi

# continue with existing non-zero, or create new list of images
if [ -s ~/.imgs.txt ]
then	# ONLY replace a missing or empty filelist (user is in middle of operations)
	exit 0	# No-Operation
else	# exclude removable media (e.g. tails persistent), Trash, {website,rsnapshot} backups
	nice find ${target}							  \
	\( \( -path	/media					-prune \) \
	-o \( -path	/home/www				-prune \) \
	-o \( -path	$HOME/.cache				-prune \) \
	-o \( -path	$HOME/.calibre				-prune \) \
	-o \( -path	$HOME/.local/share/Trash		-prune \) \
	-o \( -path	$HOME/.thumbnails			-prune \) \
	-o \( -path	$HOME/tails				-prune \) \
	-o \( -path	/home/crystalfaeries.net/.Trash-${UID}/	-prune \) \
	-o \( -path	/home/www/.Trash-${UID}/		-prune \) \
	-o \( -path	/usr/share/icons			-prune \) \
	-o \( -path	/var/cache/rsnapshot			-prune \) \
	-o \( -iname	'*.gif'		-exec du {} \; \) \
	-o \( -iname	'*.jpeg'	-exec du {} \; \) \
	-o \( -iname	'*.jpg'		-exec du {} \; \) \
	-o \( -iname	'*.png'		-exec du {} \; \) \
	-o \( -iname	'*.pnm'		-exec du {} \; \) \
	-o \( -iname	'*.svg'		-exec du {} \; \) \
	-o \( -iname	'*.tif'		-exec du {} \; \) \
	\) 2> /dev/null \
	| sort -rn \
	| cut -f2- \
	>	~/.imgs.txt	# the size sorted list of image files
fi
exit $?


syntax highlighted by Code2HTML, v. 0.9.1