Ok. The entire script is a loop.
Code:
for fname in "$1"/*; do
...
done
It creates a variable called
fname and loops over all values listed after the
in keyword.
The expression
"$1"/* is a
glob that will be expanded by bash into the list of all files in the directory
"$1". The
"$1" variable itself refers to the first command line argument of the script, so if I name the file
"script"
and execute it as
Code:
./script ./Products
the "$1" will be
"./Products". If the
Products directory contains directories
a,
b and
c, the
for line
will be expanded to
Code:
for fname in ./Products/a ./Products/b ./Products/c; do
Note that unlike some other methods, such as pasting the output of
ls, the * glob will expand into a set of correctly delimited filenames even in the
case when the filenames contain spaces.
The first thing I do with each
fname is checking that it is a directory
Code:
if [ ! -d "$fname" ]; then continue; fi
The "!" sign is a negation (logical
not), the
-d is true if its argument exists and is a directory. The line therefore means
"if
$fname is not a directory, skip the rest of the loop and continue with the next iteration"
Next part is using find (see
man find for a complete manual).
[code]find "$fname" -mindepth 1 -maxdepth 1 -mtime -90[code]
This will search all files/directories in
$fname that fit the following conditions:
-mtime -90 - was modified 90 or less days ago
-mindepth 1 -- min. level to be searched -- this prevents the directory $fname itself from being included in the list
-maxdepth 1 -- max. level to be searched -- this prevents find from searching the subdirectories of $fname recursively
The output of
find is then piped to
wc which counts the entries returned by
find. Both commands are enclosed in
$( ), which means
"run the commands in parentheses and paste their output here":
Code:
$(find "$fname" -mindepth 1 -maxdepth 1 -mtime -90 | wc -l)
The output (which is the number of files in
$fname that were modified in the last 90 days) is then compared with zero in an
if construct
Code:
if [ "$( ... )" -gt 0 ]; then
echo "$fname"
fi
which means "if there's more than zero files modified in the last 90 days, print
$fname"
So, that's about it. Hope this makes it more clear
Oh, sorry if this is more detailed than what you wanted... It's just that it is a long boring afternoon in a lonely office and I am trying to keep myself busy by writing long posts
)