On Thu, May 19, 2016 at 5:09 PM, Eric Pruitt <eric.pruitt_AT_gmail.com> wrote:
> I wrote a tool for filtering lists of files based on return codes of
> subprocesses called "query:" https://github.com/ericpruitt/query .
>
> Find all dynamically linked executables:
>
> find -type f | query sh -c 'ldd "$QUERY_FILENAME"'
>
> Find all files ending in ".json" that are malformed:
>
> find -type f -iname '*.json' | query -s ! python -m json.tool
>
> The tool should pretty portable. I haven't tested it on FreeBSD or
> OpenBSD yet, but I was able to compile it on Mac OS X. I am using
> signal(2) whose behavior varies across platforms, but I don't think that
> will be a problem in practice since the handler only calls exit(3).
> Please let me know what you think of the idea and code.
>
> Thanks,
> Eric
>
This ability is already built in to find using the -exec primary. And
newline delimited lists of files are not safe. If the program you are
piping to supports nul delimited lists you can print them in POSIX
find by doing
find . -exec printf '%s\0' {} +
and in many other finds (e.g. GNU) by doing
find . -print0
For your first example
find . -type f -exec sh -c 'ldd "$1" >/dev/null 2>&1' sh {} \; -print
or better, yet, fewer instances of sh
find . -type f -exec sh -c 'for f do ldd "$f" >/dev/null 2>&1 &&
printf %s\\n "$f"; done;:' sh {} +
These examples do just print the filenames, so they are for visual
inspection only. If you want to do something with those filenames, do
so in exec, or print them with nul delimiters (but really... just
-exec).
That being said, cool tool!
-emg
Received on Fri May 20 2016 - 16:29:28 CEST