在Unix中查找大小的文件 [英] Find files with size in Unix

查看:119
本文介绍了在Unix中查找大小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个Unix命令来打印它的大小的文件。我使用了这个,但它没有工作。

I am looking for a Unix command to print the files with its size. I used this but it didn't work.

find . -size +10000k -print.

我想打印文件的大小以及文件名/目录。

I want to print the size of the file along with the filename/directory.

推荐答案

find . -size +10000k -exec ls -sd {} +

如果您的版本 find 不会接受 + 符号(其行为更像 xargs ) ,则可以使用(GNU find xargs ,因此 find 可能支持 + 反正):

If your version of find won't accept the + notation (which acts rather like xargs does), then you might use (GNU find and xargs, so find probably supports + anyway):

find . -size +10000k -print0 | xargs -0 ls -sd

或者您可以用 + \; (和生活的相对无效率),或者你可能生活在名称空间引起的问题,并使用portable: p>

or you might replace the + with \; (and live with the relative inefficiency of this), or you might live with problems caused by spaces in names and use the portable:

find . -size +10000k -print | xargs ls -sd

-d ls 命令确保如果找到目录(不太可能,但是...),则将打印目录信息,而不是目录中的文件。如果您要查找超过1 MB的文件(作为现在删除的注释建议),您需要将 + 10000k 调整为 1000k 或可能 + 1024k +2048 (对于512字节块, -size 的默认单位)。这将列出大小,然后文件名。通过向 find 中添加 -type f 可以避免需要 -d code>命令,当然。

The -d on the ls commands ensures that if a directory is ever found (unlikely, but...), then the directory information will be printed, not the files in the directory. And, if you're looking for files more than 1 MB (as a now-deleted comment suggested), you need to adjust the +10000k to 1000k or maybe +1024k, or +2048 (for 512-byte blocks, the default unit for -size). This will list the size and then the file name. You could avoid the need for -d by adding -type f to the find command, of course.

这篇关于在Unix中查找大小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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