LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 03-17-2004, 11:29 PM   #1
akin81
LQ Newbie
 
Registered: Mar 2004
Posts: 13

Rep: Reputation: 0
counting number of files


Is there a command in Linux counting the number of files in a directory and all its subdirectories?
 
Old 03-17-2004, 11:46 PM   #2
Kovacs
Member
 
Registered: Jul 2003
Distribution: FreeBSD 8.2 RELEASE
Posts: 607

Rep: Reputation: 31
ls -R | wc -l
 
Old 03-18-2004, 02:25 AM   #3
akin81
LQ Newbie
 
Registered: Mar 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Kovacs
ls -R | wc -l
is there a better solution in stead of counting number of lines?
 
Old 03-18-2004, 02:49 AM   #4
Demonbane
Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
maybe
Code:
find . -type f | wc -l
?

that doesnt count symbolic links though
 
Old 03-18-2004, 02:56 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
None I know of in standard installations ... but you
can probaly write something in C.


Cheers,
Tink
 
Old 03-25-2004, 02:48 PM   #6
jkunkel
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
Counting number of files

Here is a small script to count the number of files directories and sym links in a directory.

----------------

let COUNT=0

for i in $1/*
do
let COUNT+=1
done

echo $COUNT

----------------

example command:

count ./

with a few more modifications to the script it could count all files in sub directories also.

Enjoy!
 
Old 03-25-2004, 02:53 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Re: Counting number of files

Quote:
Originally posted by jkunkel
----------------

let COUNT=0

for i in $1/*
do
let COUNT+=1
done

echo $COUNT

----------------
You sure that's more efficient than
Code:
ls -R | wc -l
? :)


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting number of sheets printed from a printe avirup dasgupta Linux - General 2 07-25-2005 08:36 PM
Number of Open Files rjapenga Linux - General 2 04-14-2005 02:01 AM
Large Number of files? mikeshn Linux - Security 2 01-10-2004 07:11 AM
Counting SLOC of multiple files uraja Linux - Newbie 1 09-12-2003 08:12 PM
Number of files and directories ALF Linux - Software 4 06-11-2003 11:34 AM


All times are GMT -5. The time now is 12:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration