- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- File::find question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2006 08:55 AM
05-01-2006 08:55 AM
File::find question
I would like to use File::find to traverse a directory tree find files but would like to skip some of suddirectories under that directory.
How do I do this using File::find?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2006 09:56 AM
05-01-2006 09:56 AM
Re: File::find question
A Perl question...
First, consider:
If you wanted to find all files in '/var' whose name ended in ".log" but you wanted to *skip* any within '/var/adm' you could do:
# find /var -type f ! -path "/var/adm/*" -prune -name "*.log" -print
NOW, using the above command, with *one modification*, do:
# find2perl /var -type f ! -name "/var/adm/*" -prune -name "*.log" -print
NOTE that the '-path' has been changed to '-name' and then the whole argument passed to 'find2perl'.
The generated 'wanted' subroutine should be what you seek.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2006 12:18 PM
05-01-2006 12:18 PM
Re: File::find question
My apologies, the generated code doesn't quite do what we want. Given my original shell command:
# find /var -type f ! -path "/var/adm/*" -prune -name "*.log" -print
...a 'wanted' subroutine like this should match:
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
$File::Find::name !~ /^\/var\/adm\//s &&
/^.*\.log\z/s &&
print("$name\n");
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2006 06:27 PM
05-01-2006 06:27 PM
Re: File::find question
If you want to check on the target of symbolic links too, use Cwd's realpath () or perl's readlink ().
# perl -MFile::Find -le'find(sub{$File::Find::dir=~m{pattern-for-dirs-to-skip} and return;print$File::Find::name},@ARGV)' /var /tmp
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 03:48 AM
05-02-2006 03:48 AM