Reputation: 47
I need to get the top 3 files having the latest date of modification of a sub-folders of each folder of a main folder.
The script should go through each of every sub folder of the specified main-folder and list the files having the latest date of each sub folder of the main-folder.
This script gets the latest modification date of a folder taking into consideration all the sub-folders
find /path/ -exec stat \{} --printf="%n %y\n" \; | sort -n -r | head -3
But I need to iteration through sub-folders of the main-folder to get a list of folders and filenames having the earliest date of modification of each folder.
for folder in MAINFOLDER
do
find ***folder*** exec stat \{} --printf="%n %y\n" \; | sort -n -r | head -1
loop
Upvotes: 1
Views: 1839
Reputation: 11703
Something like this?
#!/bin/bash
for folder in MAINFOLDER/*
do
find "$folder" -exec stat \{} --printf="%n %y\n" \; | sort -n -r | head -3
done
Upvotes: 1