38
find /tmp -printf '%s %p\n' |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?

2
51

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.

7
  • @don_crissti I'll never understand why people prefer random web documentation to the documentation installed on their systems (which has the added benefit of actually being relevant to their system).
    – Kusalananda
    Nov 17 '17 at 9:53
  • 1
    @Kusalananda - Well, I can think of one scenario in which people would include a link to a web page instead of a quote from the documentation installed on their system: they're not on a linux machine at the time of writing the post... However, the link should point (imo) to the official docs (hence my comment above, which, for some unknown reason, was deleted by the mods...). That aside, I fully agree with you: the OP should consult the manual page installed on their system. Nov 17 '17 at 12:52
  • 2
    @don_crissti Or they are on a server that has no manpages installed which is rather frequent.
    – runlevel0
    Feb 15 '18 at 12:10
  • 2
    @don_crissti I can think of several reasons. For starters, man pages are usually written with every feature explained, in whatever order makes sense to the programmer. That's not usually helpful at all to normal users. I've been scripting for 35 years, and these days I search stackexchange first, then worst-case (almost never) fall back to man page.
    – Jim
    Oct 26 '18 at 4:15
  • 6
    I should also add that, in addition to overwhelming and often inscrutable output of man pages for relatively inexperienced users, as a programmer/power user I'm usually looking for novel solutions that man pages don't cover. For example (just now), specific date format for 'find' command output. The man page doesn't tell you to put "%T" in front of each variable--at least not that I found even looking for that specifically. You could spend all day trying to figuring it out. (Or just give.) Whereas a search on Stack Exchange will yield that answer, clearly explained, in the first result.
    – Jim
    Oct 26 '18 at 15:24
2

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.

1

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 %p\n' get explained, others dont. @jim has mentioned the use of %T. I personally use a script with a line similar to find . -printf '%T@ %p\n' without ever being able to understand what that %T@ is. Can anybody reference an explaining source for these options not found in the manpages?

4
  • 2
    Who's this Barrett guy?
    – Kusalananda
    Oct 18 '19 at 14:43
  • 2
    @Kusalananda, Daniel J. Barrett, author of "Linux Pocket Guide", page citation refers to the second edition. Before you run to the library, be warned that the solution to this question is not to bee found in there. Otherwise a very good guide.
    – choklo
    Oct 18 '19 at 15:05
  • Might have been missing from find's manpage back in the day. You should see an entry now specifically for %Tk, where k is the same notation as used in %Ak. Which states: @ = seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
    – Nicholi
    Feb 26 '20 at 3:11
  • @Nicholi | thanks, that makes sense. Times in other formats sometimes fail to sort things nicely.
    – choklo
    Feb 26 '20 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.