Mac find和Linux find之间的区别 [英] Difference between Mac `find` and Linux `find`

查看:170
本文介绍了Mac find和Linux find之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了一个脚本作为应用程序构建过程的一部分,当我在构建服务器(Ubuntu Precise)上运行它时,它运行良好,但是当我在我的Mac上运行它时,我得到非法选项 - T。有问题的命令很简单,只是调用 find

  find -type f -not -path [...] 

在测试中,我发现这是在我的Mac上遇到麻烦的 -type 选项。如果我运行:

  find ./ -type f -not -path [...] 
code>

它可以工作,但两者都可以在Linux机器上运行(看似等价)。因此,我的问题是,OSX(BSD) find 二进制与Linux(GNU?) find 我将对脚本进行修改(在开始处添加 ./ 路径)会破坏我还没有发现的任何内容吗?

标准

a>强制执行路径(在您的示例中为 ./ )。 在MacOS上找到符合标准。

GNU find (在Linux上可用)允许路径是可选的。如果未指定,则认为当前目录是路径。在Linux上,man find表示:

  find [-H] [-L] [-P] [-D debugopts] [ - (请注意,路径是在<$ c中指定的)    

指定路径是一个好习惯。

I have inherited a script as part of a build process for an application, and when I run it on the build server (Ubuntu Precise) it runs fine, but when I run it on my mac I get "illegal option -- t". The command that has problems is simple, it's just a call to find:

find -type f -not -path [...]

On testing I have discovered that it is the -type option that has trouble on my Mac. If I run instead:

find ./ -type f -not -path [...]

It works, yet both work (seemingly equivalently) on the Linux box. Therefore my question is, are there significant differences between OSX's (BSD) find binary and the Linux (GNU?) find and will my modification to the script (adding the ./ path at the start) break anything that I haven't discovered yet?

解决方案

The standard mandates the path (./ in your example) to be mandatory. find on MacOS follows the standard.

GNU find (the one available on Linux) allows the path to be optional. If not specified, the current directory is assumed to be the path. On Linux, man find says

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

(note that path is specified within [...] denoting that it is optional.

It is a good practice to specify the path.

这篇关于Mac find和Linux find之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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