在Unix中使用bash查找指定大小的文件 [英] Find files of specified size using bash in Unix

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

问题描述

我正在寻找一个 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 findxargs,所以 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

或者您可能会用 \; 替换 +(并忍受相对低效的情况),或者您可能会遇到由名称和使用中的空格引起的问题便携式:

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

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

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中使用bash查找指定大小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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