The following code loops through ALL directories under current path to perform a count on compressed xml files:for i in *xml.gz; do     echo XML ${PWD##*/} $i $(gunzip -c $i | echo scale=0; `wc -l` | bc -l); done I'm looking for a way to perform the loop say on the last 5 directories in order to prevent counting directories previously counted (and cut back execution time) The for loop allows specifying certain directories, but I still need to only count xml files. Can't find any syntax to do both. 
Loop through specific set of directories
shell;scripting;directory;xml