macos find 缺少选项 -printf,现在怎么办?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/752818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
find lacks the option -printf, now what?
提问by Léo Léopold Hertz ??
I have not found a reason why Mac's find does not have the option -printf. Apple normally decides to take options out which are not orthogonal to the other commands?
我还没有找到 Mac 的 find 没有选项 -printf 的原因。Apple 通常决定去掉与其他命令不正交的选项?
How can you reach the same result as the following command in Macwithout coreutils?
在没有 coreutils 的情况下,如何在 Mac 中达到与以下命令相同的结果?
find . -printf "%i \n" // command in Ubuntu
采纳答案by ephemient
It's not that Apple removes options, it's that OS X's UNIX underpinnings are mostly derived (circuitously) from FreeBSD, many parts of which can be traced back to the original UNIX... as opposed to the GNU utilities, which are re-implementations with many features added.
并不是 Apple 删除了选项,而是 OS X 的 UNIX 基础主要(迂回地)从 FreeBSD 派生而来,其中许多部分可以追溯到原始 UNIX……而不是 GNU 实用程序,后者是用添加了许多功能。
In this case, FreeBSD's find(1)
doesn't support -printf
, so I wouldn't expect OS X's to either. Instead, this should work on a BSD-ish system:
在这种情况下,FreeBSDfind(1)
不支持-printf
,所以我不希望 OS X支持。相反,这应该适用于 BSD-ish 系统:
find . -print0 | xargs -0 stat -f '%i '
It'll fail on a GNU-userland system, though, where you'd write xargs -0 -r stat -c '%i '
because xargs(1)
and stat(1)
behavior is different.
它会失效了一个GNU用户态的系统上,不过,在那里你会写xargs -0 -r stat -c '%i '
,因为xargs(1)
和stat(1)
行为是不同的。
回答by abkrim
MAc OS X find binary doesn't support the -printf command. Install brew install findutils
on your mac. This install gfind with -printf option.
MAC OS X find binary 不支持 -printf 命令。brew install findutils
在您的 Mac 上安装。使用 -printf 选项安装 gfind。
回答by dmckee --- ex-moderator kitten
回答by Sam
Alternatively, you could just
或者,你可以
find . -type f -exec stat -f "%z %N" {} \;
Granted, this isn't how you would do the same thing on linux, but works for MacOS
当然,这不是你在 linux 上做同样事情的方式,但适用于 MacOS
find . -type f -exec stat -c "%s %N" {} \;
produces similar (not same, but close) output on linux.
在 linux 上产生类似(不相同,但接近)的输出。
回答by bendin
Ubuntu ships with the GNU version of find, which is more featureful than Mac OS X's find, which is of BSDlineage.
Ubuntu 附带了GNU 版本的 find,它比 Mac OS X 的 find 更有特色,后者属于BSD谱系。
In fact, most of the Ubuntu's user-land utilities are from the GNU project. (Thus you'll sometimes hear Linux-based systems referred to as "GNU/Linux".)
事实上,大多数 Ubuntu 的用户空间实用程序都来自 GNU 项目。(因此,您有时会听到称为“GNU/Linux”的基于 Linux 的系统。)