I have found the following which will list the files in all subdirectories, hide the last 5, and then delete the rest:
find -type f -printf '%T@ %P\n' | sort -n | cut -d' ' -f2- | head -n -5 | xargs rm
Unfortunately if I don't know how many subdirectories there are, it won't delete the correct number of files. Does anyone have a way to transverse each directory, and then delete all but the newest of file in each subdirectory?
Directory structure would be the following:
-> Base Directory -> Parent Directory -> Child directory
I'd write a script.
It would be a recursive function:
In case lot of subdirectories it may be memory problem because of the recursive function.