Next: , Up: Format Directives   [Contents][Index]


3.2.2.1 Name Directives

%p

File’s name (not the absolute path name, but the name of the file as it was encountered by find - that is, as a relative path from one of the starting points).

%f

File’s name with any leading directories removed (only the last element). That is, the basename of the file.

%h

Leading directories of file’s name (all but the last element and the slash before it). That is, the dirname of the file. If the file’s name contains no slashes (for example because it was named on the command line and is in the current working directory), then “%h” expands to “.”. This prevents “%h/%f” expanding to “/foo”, which would be surprising and probably not desirable.

%P

File’s name with the name of the command line argument under which it was found removed from the beginning.

%H

Command line argument under which file was found.

For some corner-cases, the interpretation of the ‘%f’ and ‘%h’ format directives is not obvious. Here is an example including some output:

$ find \
  . .. / /tmp /tmp/TRACE compile compile/64/tests/find \
  -maxdepth 0 -printf '%p: [%h][%f]\n'
.: [.][.]
..: [.][..]
/: [][/]
/tmp: [][tmp]
/tmp/TRACE: [/tmp][TRACE]
compile: [.][compile]
compile/64/tests/find: [compile/64/tests][find]