find2perl
Convert find command to Perl code
SYNOPSIS
find2perl [path...] [expression]
PARAMETERS
-h, --help
Print brief help message and exit
-m, --man
Display full manual page
--print0
Use \0 (NUL) as pathname separator instead of ':'
--never
Suppress filename printing (for testing/debugging)
DESCRIPTION
find2perl is a Perl utility that converts find(1) command lines or its output into equivalent Perl code using the File::Find module. It replicates the directory traversal and file selection logic, making it ideal for embedding complex searches in Perl scripts without external process invocation.
The tool accepts paths and expressions identical to find, such as directories to start from and predicates like -name, -type, -mtime, -size, -user, and actions like -print. For example, running find2perl /home -name '*.pl' -mtime -7 generates a self-contained Perl script that finds all Perl files modified in the last week under /home. Piping find output also works: find . -name '*.c' | find2perl.
The output is a ready-to-run script with use File::Find;, directory specification, and a wanted() subroutine implementing the conditions. It handles logical operators (-and, -or, !), parentheses for grouping, and common actions. This improves performance for repeated use and enhances portability across systems.
CAVEATS
Not all advanced find features translate perfectly (e.g., some -exec variants or findutils extensions); always verify generated script. Limited support for very complex expressions with deep nesting.
BASIC EXAMPLE
find2perl /etc -name '*.conf' -print
Outputs Perl script searching /etc for .conf files.
PIPED USAGE
find . \( -type f -o -type l \) -print | find2perl
Translates piped find output to Perl code.
HISTORY
Developed by Paul R. Brown; included in Perl core since version 5.005 (1998), with updates for better find compatibility in later releases like Perl 5.6+.


