本文介绍了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 |tail -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.

我该如何解决这个问题?

How could I please fix that?

推荐答案

这不是很漂亮,但很管用:

This is not pretty but it works:

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

这篇关于Bash 脚本:删除最旧的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:34