- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Best way to find out number of files
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
Discussions
Discussions
Forums
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
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-20-2004 01:16 PM
тАО05-20-2004 01:16 PM
Can anybody suggest the best method to count number files under any given directory other than "ls" ?.
This is a JFS filesystem and logically a directory file should have a list of inodes (?) and I would like to count them.
Regds,
Kaps
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2004 01:36 PM
тАО05-20-2004 01:36 PM
Solutionis pretty easy
but if you want another way:
#!/usr/bin/perl
opendir DH1,$ARGV[1];
@arry = readdir(DH1);
closedir DH1;
print $#arry + 1,"\n";
You should add some error checking and maybe some stat commands to look for certain types of files but that should get you started.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2004 02:02 PM
тАО05-20-2004 02:02 PM
Re: Best way to find out number of files
try this at the directory you are interested in:
# ls|wc -l
wc counts the number of lines which is equivalent to the number of files in that directory.
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2004 02:05 PM
тАО05-20-2004 02:05 PM
Re: Best way to find out number of files
find /DIRNAME -type f |wc -l
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2004 02:21 PM
тАО05-20-2004 02:21 PM
Re: Best way to find out number of files
When I invoke it with directory as an argument, why is it printing "0" when there are multiple files in it ?.
./script1 /u/hcsg41/OLDLOGS
0
Am I wrong in syntax ?. I am not good at perl
Joseph, I clearly mentioned other than "ls"
Tamil , I have already tried find but it is cpu intensive as I have 9,00,000 files in a filesystem on which I want to count nofiles for duirectories! (some bloody developer screwed it up)
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2004 09:21 PM
тАО05-20-2004 09:21 PM
Re: Best way to find out number of files
strings $DIR | wc -l
1) It doesn't use ls ;)
2) You'll be able to see strange thing : file that were deleted
More seriously, I supose the fastest result should be obtenaid with C using some file stat API.
Cheers
Nicolas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2004 12:17 AM
тАО05-21-2004 12:17 AM
Re: Best way to find out number of files
If you want to count the files recursively you can try:
find directory -print | wc -l
if you want count only regular files or directories do:
find directory -type f -print |wc -l
or
find directory -type d -print |wc -l
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2004 12:31 AM
тАО05-21-2004 12:31 AM
Re: Best way to find out number of files
find /directory/* -prune | wc -l
"-prune" does not look into subdirs.
if you wanna only files:
find /directory/* -type f -prune | wc -l
if you wanna count "dot-files" as well
find /directory/* /directory/.* | wc -l
"find" is better performing if you have lots and lots of entries in that directory, but normally "ls" is as good as this and easier to use.