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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityfind /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?
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.
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.
Barrett 2012 says on page 74:
"-printf
string
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?
-printf "%TY-%Tm-%TdT%TT %p\n"
(including the double quotes) prefixes the file name with the modification time in ISO 8601 format. (On some systems, the seconds part is in nanosecond resolution which may ruin the display - a post filter, likeperl -nle 's/(\d\dT[^\.]+\.\d\d\d)\d+/$1/g; print $_'
, may be required).