繁体   English   中英

从ls -1hl命令的输出中查找超过100 MB的文件

[英]find files more than 100 MB from ls -1hl command's output

我在某些目录上执行ls -1lh命令,并在GUI上显示输出。

ls命令中使用的选项的描述

1 --> print one file/directory in one line
l --> long listing
h --> human readable format (converting in KB, MB, G)

现在我从ls -1lh命令中提取了大小:-

size = ["100","9.6K","12M","79M","679M","222K","23","132M","3G","1.3G"]

现在我想找出python中超过100M的大小

我的方法是什么? 我必须使用ls -1lh命令,因为用户想查看Directoires上的长列表

units = dict(K=1024, M=1024*1024, G=1024*1024*1024)
def parse_size(s):
    times = units.get(s[-1:], 1)
    if times == 1:
        return float(s)
    else:
        return float(s[:-1]) * times

用法:

>>> size = ["100","9.6K","12M","79M","679M","222K","23","132M","3G","1.3G"]
>>> threshold = parse_size('100M')
>>> print [s for s in size if parse_size(s) >= threshold]
['679M', '132M', '3G', '1.3G']

顺便说一句,如果要获取大于100MB的文件列表,如何使用find find -maxdepth 1 -size +100M

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM