home

Quickies, by Andrea Olivato

text

Cycle all folder’s file and get each name in #bash

This is pretty useful if you need to do some operations on certain files in a folder. In the example I’m cycling all files in the apache log folder, selecting only the .log files and then get the basename (no path) of the log.

DIR="/var/log/apache2";
for FILE in ${DIR}/*.log
do
        FILE=`basename $FILE`;
        echo "Let's do some op on $FILE";
done

2 years ago

July 6, 2009
Comments (View)
blog comments powered by Disqus