Linux - Save only recent 10 folders and delete the rest

后端 未结 6 1744
借酒劲吻你
借酒劲吻你 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

    If the directories' names contain the date one can delete all but the last 10 directories with the default alphabetical sort

    ls -d */ | head -n -10  | xargs rm -rf
    

提交回复
热议问题