Gossamer Forum
Home : General : Internet Technologies :

get recursive count of files/directories from shell

Quote Reply
get recursive count of files/directories from shell
Can anyone recommend a shell command for getting a recursive count of files and subdirectories?

Thanks.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] get recursive count of files/directories from shell In reply to
find . | wc -l

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] get recursive count of files/directories from shell In reply to
Thanks. That works great on my linux machine, but I'm trying it on a Solaris box and getting a number that I'm sure is way too low. Any idea why it might work differently on Solaris?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] get recursive count of files/directories from shell In reply to
Might be a different option to wc. Try: wc --help to see what options there are:

Code:
[root@ns1 root]# wc --help
Usage: wc [OPTION]... [FILE]...
Print line, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -,
read standard input.
-c, --bytes, --chars print the byte counts
-l, --lines print the newline counts
-L, --max-line-length print the length of the longest line
-w, --words print the word counts
--help display this help and exit
--version output version information and exit

Report bugs to <bug-textutils@gnu.org>.
[root@ns1 root]#

You want to count lines.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] get recursive count of files/directories from shell In reply to
Alternatively:

find . | perl -le 'while (<>) { $count++; }; print $count'

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] get recursive count of files/directories from shell In reply to
Thanks, Alex. Actually, I think it was working, but I was forgetting about some directory mapping on the server. With that in mind, I used:

find . -follow | wc -l

The only problem with that is that some symlinks resulted in double counting...

But I think I've got the basic concept figured out anyway.

Thanks for your help.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund