如何删除编号最高的名字的目录? [英] How can I delete the directory with the highest number name?

查看:79
本文介绍了如何删除编号最高的名字的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含子目录,一些他们的名字是数字的目录。不看,我不知道这些数字是什么。如何删除子目录数字最高的名字吗?我估计解决方案可能子目录逆转进行排序,然后选择第一个子目录以数字开头,但我不知道该怎么做。谢谢你的帮助。


解决方案

  CD $ yourdir #go到该目录
 LS -q -p | #list所有文件直接在目录,使目录结尾/
 的grep'^ [0-9] * / $'| #选择目录(结束与/),其名称由数字
 排序-n | #sort数字
 尾-n1 | #SELECT最后一个(最大的)
 xargs的-r命令rmdir #OR RM -r如果非空

建议运行它首先没有的xargs -r命令rmdir 的xargs -r RM -r 部分,以确保您删除正确的事情。

I have a directory containing sub-directories, some of whose names are numbers. Without looking, I don't know what the numbers are. How can I delete the sub-directory with the highest number name? I reckon the solution might sort the sub-directories into reverse order and select the first sub-directory that begins with a number but I don't know how to do that. Thank you for your help.

解决方案

 cd $yourdir             #go to that dir
 ls -q -p     |             #list all files directly in dir and make directories end with /
 grep '^[0-9]*/$' |      #select directories (end with /) whose names are made of numbers
 sort -n |               #sort numerically
 tail -n1 |              #select the last one (largest)
 xargs -r rmdir          #or rm -r if nonempty 

Recommend running it first without the xargs -r rmdir or xargs -r rm -r part to make sure your deleting the right thing.

这篇关于如何删除编号最高的名字的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆