0

I have a directory with about 130 subdirectories in it.

Here's the main directory:

/home/data/all/

Subdirectories are like this:

/home/data/all/whatever
/home/data/all/test
/home/data/all/information

I want to have exactly 100 subdirectories in this main directory. The oldest subdirectories (based on last modified date) should automatically be removed to make sure there's always exactly 100 directories.

Is there any way to do this with a one-liner?

Edward
  • 343
  • 6
  • 12
  • 2
    You already have a nice answer [\[ here \]](http://unix.stackexchange.com/a/28947/25919). – sjsam Jul 13 '16 at 04:45
  • 3
    I'm voting to close this question as off-topic because this question belongs to [\[ UL \]](http://unix.stackexchange.com) and already has an answer there as mentioned in Comment#1 – sjsam Jul 13 '16 at 05:39

1 Answers1

0
ls -A1td */ | tail -n +100 | xargs rmdir

You should test this first on your backup directory,

chicks
  • 2,393
  • 3
  • 24
  • 40
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24