Bash scripting: Deleting the oldest directory

前端 未结 4 1119

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条回答
  •  萌比男神i
    2020-12-19 08:41

    
    find directory_name -type d -printf "%TY%Tm%Td%TH%TM%TS %p\n" | sort -nr | tail -1 | cut -d" " -f2 | xargs -n1 echo rm -Rf
    
    You should remove the echo before the rm if it produces the right results

提交回复
热议问题