Linux - Save only recent 10 folders and delete the rest

后端 未结 6 1742
借酒劲吻你
借酒劲吻你 2021-02-04 14:14

I have a folder that contains versions of my application, each time I upload a new version a new sub-folder is created for it, the sub-folder name is the current timestamp, here

6条回答
  •  心在旅途
    2021-02-04 15:03

    There you go. (edited)

    ls -dt */ | tail -n +11 | xargs rm -rf

    First list directories recently modified then take all of them except first 10, then send them to rm -rf.

提交回复
热议问题