52
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?

1 Answers1

64

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.

Hennes
  • 2,038
  • 1
    @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 09:53
  • 2
    @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. – don_crissti 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
  • My manual page tend to be from FreeBSD though. Unless I happen to have a Linux VM within reach. And I have the impression that most questions are GNU/Linux based. – Hennes Feb 16 '18 at 16:16
  • 4
    @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 04:15
  • 8
    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
  • man find|wc -c results about 78 kByte, this is why your answer is useful. – peterh Jan 26 '21 at 14:56
  • If anyone needs explanations of commands take a look at this page where you write the command and explains every part, https://explainshell.com/explain?cmd=find+%2Ftmp+-printf+%27%25s+%25p%5Cn%27+%7Csort+-n+-r+%7C+head – lesolorzanov May 30 '23 at 08:14