I am working on a bash script to compress the images in my Wordpress folders. The wordpress folder structure is as follows:
> wp-content/uploads/2014/01/filename.jpg > wp-content/uploads/2014/02/filename.jpg > wp-content/uploads/2014/03/filename.jpg > wp-content/uploads/2014/04/filename.jpg > > i.e. wp-content/uploads/YEAR/MONTH/filename.jpg
In the uploads folder I have a number of other folders (which were created when plugins were installed), so I'm trying to loop through the folders with numeric names only and then compress the images. Here is what I have so far:
DIR_UPLOADS=/home/html/wp-content/uploads/ cd ${DIR_UPLOADS} for d in *; do # First level i.e. 2014, 2013 folders. regx='^[0-9]+$' # Regular Expression to check for numerics. if [[$d =~ $regx]]; then # Check if folder name is numeric. #echo "error: Not a number" >&2; exit 1 cd $d for z in *; do # Second level i.e. the months folders 01, 02 etc. cd $z for x in *; do # Third level the actual file. echo 'Compress Image' done done fi done
I'm trying to use reg ex to detect the numeric folders, this isn't quite right, but I think I'm close.