Script to keep only the last three directories under each of the subdirectory

Multi tool use


Script to keep only the last three directories under each of the subdirectory
Assume that I have a directory structure as follows:
applications
│
├── configs
│ ├── 1.0.0.1
│ └── 1.0.2.1
│
├── logs
│ ├── l1.0.3
│ └── l2.0.4
│
└── src
├── s1.p.8
├── s1.p.9
└── s2.p.10
Now I want to delete the folders under each subdirectory under applications directory and keep only the last three under each subdirectory
Eg: under applications directory we have like configs, logs,src, test, etc.
The requirement is that I need to keep only the last three directories under each of these directories(configs, logs,src, test, etc).
Thanks.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.