find lacks the option -printf, now what?

MacosFindPrintf

Macos Problem Overview


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?

How can you reach the same result as the following command in Mac without coreutils?

find . -printf "%i \n"         // command in Ubuntu

Macos Solutions


Solution 1 - Macos

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.

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:

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.

Solution 2 - Macos

MAc OS X find binary doesn't support the -printf command. Install brew install findutils on your mac. This install gfind with -printf option.

Solution 3 - Macos

Well, ephemient and bendin nailed the cause.

I'd add that there is nothing stopping you from installing GNU find (from the findutils) if you need it. If you use fink there is a findutils package. MacPorts has it too.

Solution 4 - Macos

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

find . -type f -exec stat -c "%s %N" {} \;

produces similar (not same, but close) output on linux.

Solution 5 - Macos

Ubuntu ships with the GNU version of find, which is more featureful than Mac OS X's find, which is of BSD lineage.

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".)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLéo Léopold Hertz 준영View Question on Stackoverflow
Solution 1 - MacosephemientView Answer on Stackoverflow
Solution 2 - MacosabkrimView Answer on Stackoverflow
Solution 3 - Macosdmckee --- ex-moderator kittenView Answer on Stackoverflow
Solution 4 - MacosSamView Answer on Stackoverflow
Solution 5 - MacosbendinView Answer on Stackoverflow