使用 GNU find
:
find ~/Documents/ -type d -name images -printf '%h\\n'\n
Run Code Online (Sandbox Code Playgroud)\n来自-printf
以下部分man find
:
%h Leading directories of file's name (all but the last ele\xe2\x80\x90\n ment). If the file name contains no slashes (since it is\n in the current directory) the %h specifier expands to\n `.'.\n
Run Code Online (Sandbox Code Playgroud)\n