bash脚本编程:删除最早的目录 [英] Bash scripting: Deleting the oldest directory
本文介绍了bash脚本编程:删除最早的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要寻找最古老的目录(目录),并将其删除。我使用的是以下内容:
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 -1T |尾-1
确实如此给我的最古老的目录,问题是,它不删除的目录,而且它也列出文件。
ls -1t | tail -1
does indeed gives me the oldest directory, the the problem is that it is not deleting the directory, and that it also list files.
我怎么可能请解决呢?
推荐答案
这是不是pretty但它的作品:
This is not pretty but it works:
rm -R $(ls -lt | grep '^d' | tail -1 | tr " " "\n" | tail -1)
这篇关于bash脚本编程:删除最早的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文