Is there any way to get `find` not to quote the result of -printf

I want to use the find command with -printf '%h' to print the leading directories, separated by the nul character. Since I am using , I don’t need, and don’t want find to quote the results, as described in the "UNUSUAL FILENAMES" section of the find manpage.

Is there any way to tell find "I really know what I’m doing" and not do the quoting when using the -printf option?

Asked By: Thayne

||

Presumably you want to capture the output of find in a pipeline. In such instances the quoting is not enabled (it’s only used for output to a terminal).

Example:

mkdir $'two linendirectory'
( cd two* && touch file )

Then,

find two* -printf '%hn'

.
two line?directory

But,

find two* -printf '%hn' | cat

.
two line
directory

This is explained in man find (GNU) in the section UNUSUAL FILENAMES:

-printf, -fprintf If the output is not going to a terminal, it is printed as-is.

Otherwise (i.e. to a terminal),

[…] The directives %f, %h, %l, %p and %P are quoted.

I should note that I have not been able to see a "quoted" file or directory name, despite what the documentation writes. I’ve only been able to see non-printing characters replaced with ? per my example above.

Answered By: Chris Davies
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.