Bash scripting: Deleting the oldest directory

前端 未结 4 1135

I want to look for the oldest directory (inside a directory), and delete it. I am using the following:

rm -R $(ls -1t | tail -1)

ls -

4条回答
  •  余生分开走
    2020-12-19 08:50

    This is not pretty but it works:

    rm -R $(ls -lt | grep '^d' | tail -1  | tr " " "\n" | tail -1)
    

提交回复
热议问题