- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl or Alternative: Count Files and Directories w...
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
01-22-2013 02:35 AM
01-22-2013 02:35 AM
hello,
i want to count files and directories with one command.
my alternative due 2 find commands :
find <dir> -type f | wc -l
find <dir> -type d | wc -l
i adapted the last perl one liner of :
dir="/tmp" perl -MFile::Find -le '$dir=$ENV{"dir"};$cnt_d=0;$cnt_f=0;find(sub{-d and ++$cnt_d;-f and ++$cnt_f;},$dir);END{print "$cnt_f:$cnt_d"}'
questions
- is the a better way to pass the directory to perl one liner ?
- better handling to count files and directories ?
why i want to count with one command : we have huge filesystems where find runs a long time
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2013 11:01 PM
01-22-2013 11:01 PM
SolutionYou could do something like this to give you a list of files with a "F" or "D":
find path -type d -exec echo D {} \; -o -type f -exec echo F {} \;
But this invokes echo for each file.
You could do this: find path -exec ll -dog {} + | magic-script
This will invoke ll for huge number of files. All you magic script needs to do is look for the leading "d" and count up the two types of "files".
Otherwise using perl to both find and count seems fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2013 07:19 AM
01-25-2013 07:19 AM
Re: Perl or Alternative: Count Files and Directories with one command
hello,
You could do something like this to give you a list of files with a "F" or "D": find path -type d -exec echo D {} \; -o -type f -exec echo F {} \;
the output is handle by example a "awk" like this ?
find . -type d -exec echo D {} \; -o -type f -exec echo F {} \; | awk ' BEGIN { cnt_d = 0; cnt_f = 0; } /^D/ { cnt_d++ } /^F/ { cnt_f++ } END { print cnt_f ":" cnt_d } '
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2013 07:41 AM
01-25-2013 07:41 AM
Re: Perl or Alternative: Count Files and Directories with one command
Information about performance ( 60000 files and 350 directories )
1. : perl
2. : find ( with 2 seperate commands)
3. find with echo ( very,very slow )
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2013 10:03 AM - edited 01-25-2013 11:38 AM
01-25-2013 10:03 AM - edited 01-25-2013 11:38 AM
Re: Perl or Alternative: Count Files and Directories with one command
>the output is handle by example a "awk" like this ?
Exactly.
>3. find with echo (very, very slow)
Yes, that's why I suggested the "-exec ll -dog {} +" solution. With a slightly modified awk script.