FG
💻 Software

Delete all files (except the four newest) throughout directories using a Bash script

Fresh5 days ago
Mar 15, 20267115 views
Confidence Score0%
0%

Problem

I'm looking for a Bash script that will go into a list of directories and delete all but the four most recently created files. How can I do this?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Delete all files (except the four newest) throughout directories using a Bash script

Low Risk

Remove the when you're satisfied that's the result you want. If you have filenames with spaces, more work is required.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment