For loop, find, executing scripts, clean empty directories PDF Print E-mail
User Rating: / 2
PoorBest 
Written by Bart Dorlandt   
Friday, 29 June 2007 00:20

Echo all directories in the subdir: /var/www/upload/foto/albums

for x in `find /var/www/upload/foto/albums -type d ` ; do echo $x  ; done

Go into every directory and execute the script resize. This script can be found here.

for x in `find /var/www/upload/foto/albums -type d` ; do cd $x ; \
    /home/bart/scripts/image/resize.sh 800  ; done

Go into every directory that hasn't the name resize and move all the contents of the directory resize into the directory below.

for x in `find /var/www/upload/foto/albums -type d | grep -v resize`  ; do cd $x ; mv resize/* .  ; done

Remove all empty directories.

find . -depth -type d | xargs rmdir 2>/dev/null

 

for more examples on how to use find, please take a look here

Last Updated on Tuesday, 01 April 2008 11:13