find2perl
Convert find command to Perl code
SYNOPSIS
find2perl expression
PARAMETERS
find expression elements
find2perl does not have its own distinct command-line options in the traditional sense. Instead, it interprets and translates the complex expression arguments that are typically passed to the find command. Therefore, the 'parameters' it accepts are actually the various primaries, options, and operators used in find expressions. Below are some of the most common find elements that find2perl can translate:
-name pattern: Translates conditions based on file name matching pattern.
-type c: Converts conditions based on file type (e.g., 'f' for file, 'd' for directory).
-size n[c]: Handles conditions related to file size.
-mtime n: Processes criteria based on the file's last modification time.
-exec command: Translates the execution of an external command for found files.
-ok command: Similar to -exec, but includes user confirmation.
-print: Converts the action of printing the file name.
-ls: Translates the action of printing file details in 'ls' format.
-a (or implicit): Represents a logical AND operator between expressions.
-o: Represents a logical OR operator between expressions.
!: Represents a logical NOT operator.
( expr ): Allows grouping of expressions to control operator precedence.
DESCRIPTION
The find2perl command translates command-line arguments that would typically be used with the find utility into an equivalent Perl script. Its primary purpose is to help users understand how find's complex logic of file system traversal and conditional actions can be implemented in Perl. It essentially generates Perl code that mimics the search criteria and actions specified in the find command. This generated script can then be examined, modified, or executed. While the resulting Perl code might not always be the most optimized or idiomatic, it provides a functional translation, making it a valuable tool for debugging find expressions, learning Perl scripting for file system operations, or as a starting point for more complex custom scripts. It handles most of find's primaries like -name, -type, -size, -mtime, -exec, -print, and logical operators like and (-a), or (-o).
CAVEATS
The Perl code generated by find2perl is often verbose and not optimized for performance or readability. It's a direct translation rather than an idiomatic Perl script. It might not handle all edge cases or the most obscure find options perfectly. Users often need to clean up or optimize the generated code for production use. It also implicitly adds a print action if no other action is specified, similar to find versions older than GNU find 4.2.0.
HISTORY
find2perl is part of the findutils package, which provides core utilities for finding files. Its development is tied to the evolution of the find command itself. It was introduced as a utility to help bridge the gap between shell scripting with find and more complex automation using Perl, at a time when Perl was a dominant scripting language for system administration tasks. Its purpose remains largely didactic and as a quick translation tool rather than a generator of production-ready code.