We have been covering up find command line statements for a while. Now here's a quick entry on how to convert find command line statements into its equivalent and executable perl codes.
Find2perl is a little translator to convert find command lines to equivalent Perl code. The resulting code is typically faster than running find itself. Find2Perl is part of perl package, which is installed by default perl installation.
In shorter words, find2perl translate find command lines to its Perl code.
Find2Perl follows the below command line format
find2perl [path] [switches] [output-perl-file]
Here are several find2perl command usage.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# find2perl /tmp -name "*.JPG" > sample.pl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make the equivalent perl code executable by root like so
# chmod 700 sample.pl
View the generated perl codes equivalent to recently issued find command
# cat sample.pl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/tmp');
exit;
sub wanted {
/^.*\.JPG\z/s
&& print("$name\n");
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More find2perl examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# find2perl /tmp -name "*.jpg" -depth -print -ls > sample2.pl
# find2perl /tmp -name "*.JPG" -depth -atime -2 -print > > sample3.pl
# find2perl /tmp -iname "*.JPG" -type f -depth -atime -2 -print > sample4.pl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Works perly codes!
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2007
(340)
-
▼
December
(38)
- Holiday Linux
- HowTo: Chikka messenger over GAIM Pidgin Messenger
- HowTo: Rename Multiple Files Without A Script
- HowTo: KDocker/AllTray - System Tray Docking
- HowTo: Thunderbird - News/Feed Reader
- HowTo: ThinFeeder - RSS/RDF/Atom Aggregator
- HowTo: Sage - Firefox Feed Reader Extension
- HowTo: Snownews - RSS/RDF Newsreader
- HowTo: Planet - RDF/RSS/Atom Feed Aggregator
- HowTo: Liferea - RSS/RDF Feed Reader
- HowTo: Blam - RSS/RDF Feed Reader
- Switching Hospital Systems to Linux
- HowTo: CSS Editor and Validator Install
- HowTo: Ebook Reader Install
- vertito's blogspot anniversary
- HowTo: Install 113 Amazing Fedora Games Part 8
- HowTo: Install 113 Amazing Fedora Games Part 7
- HowTo: Install 113 Amazing Fedora Games Part 6
- HowTo: Install 113 Amazing Fedora Games Part 3
- HowTo: Install 113 Amazing Fedora Games Part 2
- HowTo: Thunar File Manager
- HowTo: LeafPad Extremely Fast Text File Editor
- HowTo: View Bzipped file On-The-Fly
- HowTo: TuxPaint Drawing Program Installation
- HowTo: InkScape Drawing Program Installation
- HowTo: Adobe Flash Player on Fedora 8
- HowTo: Install Digital Comic Reader
- HowTo: Install 113 Amazing Fedora Games
- HowTo: Translate Find Statements to Perl Codes
- HowTo: Single Step VirtualBox Installation on Fedo...
- CLI Tip: Control Terminal Keystroke Combinations
- CLI Tip: Clearing Terminal Screen
- HowTo: Linux Aliasing Aliases
- HowTo: Move Multiple Files Recursively
- HowTo: Rename multiple files recursively
- HowTo: Strip Non-Directory Path Suffix from FileName
- HowTo: Generate Pronounceable Random Passwords
- HowTo: Determine RedHat and Fedora release version
-
▼
December
(38)
Monday, December 3, 2007
HowTo: Translate Find Statements to Perl Codes
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
0 comments:
Post a Comment