Explanation of % directives in find -printf

find /tmp -printf '%s %pn' |sort -n -r | head

This command is working fine but what are the %s %p options used here? Are there any other options that can be used?

Asked By: Sandjaie Ravi


What are the %s %p options used here?

From the man page:

%s File’s size in bytes.

%p File’s name.

Scroll down on that page beyond all the regular letters for printf and read the parts which come prefixed with a %.

%n Number of hard links to file.

%p File’s name.

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

%s File’s size in bytes.

%t File’s last modification time in the format returned by the C `ctime’ function.

Are there any other options that can be used?

There are. See the link to the manpage.

Answered By: Hennes

Barrett 2012 says on page 74:

-printfstring print the given string, which may have substitutions applied to it in the manner of the C library function printf().”

and recommends, of course, the manpage for the full list of options. While things like find . -printf '%s %pn' get explained, others dont. @jim has mentioned the use of %T. I personally use a script with a line similar to find . -printf '%T@ %pn' without ever being able to understand what that %T@ is. Can anybody reference an explaining source for these options not found in the manpages?

Answered By: choklo

A bit late for an answer, but I found a handy list of the options here:

Explainshell, find -printf options

It is indeed already in the man page, but this one has a nicer format (and you can put it behind a transparent shell tab.

Answered By: runlevel0
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.