I am trying to set-up an automatic way, for a given folder, to remove all its subfolders but the most recent created ones.
For instance, I would like to keep only the 3 most recent subfolders, and remove all the other ones.
Imagine the given folder:
/some/specific/folder /subfolder1 /subfolder2 /subfolder3 /subfolder4 /subfolder5 /subfolder6 /subfolder7 /subfolder8 /subfolder9 /subfolder10
I would like to delete all subfolders but keep
For now, I managed to list the files I would like to keep, but how to "reverse" it within a shell command?
cd /some/specific/folder/ ls -tr | head -3 # Gives the following result subfolder8 subfolder9 subfolder10 # And I am looking for the following : subfolder1 subfolder2 subfolder3 subfolder4 subfolder5 subfolder6 subfolder7