0

The printf statement :

find directory1 -type d -printf "%P\n" | sort > file1

in the answer https://superuser.com/a/166322/856910 includes a format specifier %P. From the output of this command, I find that it removes the ./ at the beginning of a line: from ./foo to foo. What is the exact meaning of this specifier? I can't find it from man printf.

3
  • What man page exactly? The answer that states "read the man find, not man printf" is good, but I think you may have confused three printfs, not only two. The title mentions "Bash printf". In Bash printf is a builtin. See this answer. man bash (or help printf in Bash) describes the builtin. The builtin is the only printf I would call "Bash printf". If by "man page" you meant man printf, then it's about another printf, mostly equivalent, still separate. Finally the -printf action of your find is yet another entity. Commented Jun 20, 2023 at 10:32
  • (cont'd) A remote possibility is you meant man find, but somehow man find in your OS describes a different implementation of find than you actually run. Unlikely, as in this case you would probably write "find printf", not "Bash printf" in the title. Anyway, what man page do you mean exactly? Please edit the question and clarify. Commented Jun 20, 2023 at 10:42
  • I mean man printf, so yes, I am confused by the parameters, thinking that it's the "format specifier" of printf instead of parameter of find. Thanks for the explanation.
    – Leo
    Commented Jun 22, 2023 at 15:34

2 Answers 2

4

You need to read the man find, not man printf or man bash/help printf.

%P File's name with the name of the starting-point under which it was found removed.

0

%P means "the file path with the starting point removed." Thus, it removes the ./ as you have found.

1
  • You need to add more details as your answer is almsot the same as the earlier one above.
    – Destroy666
    Commented Jun 20, 2023 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .