Bash 脚本:删除最旧的目录
我想查找最旧的目录(目录内),然后将其删除。我正在使用以下
rm -R $(ls -1t | tail -1)
命令: ls -1t | tail -1 确实给了我最旧的目录,问题是它没有删除该目录,而且它还列出了文件。
我该如何解决这个问题?
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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这也适用于名称包含空格、制表符或以“-”开头的目录。
This works also with directory whose name contains spaces, tabs or starts with a "-".
这并不漂亮,但它有效:
This is not pretty but it works:
You should remove the echo before the rm if it produces the right results
You should remove the echo before the rm if it produces the right results