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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-17-2004, 10:29 PM
|
#1
|
LQ Newbie
Registered: Mar 2004
Posts: 13
Rep:
|
counting number of files
Is there a command in Linux counting the number of files in a directory and all its subdirectories?
|
|
|
03-17-2004, 10:46 PM
|
#2
|
Member
Registered: Jul 2003
Distribution: FreeBSD 8.2 RELEASE
Posts: 607
Rep:
|
ls -R | wc -l
|
|
|
03-18-2004, 01:25 AM
|
#3
|
LQ Newbie
Registered: Mar 2004
Posts: 13
Original Poster
Rep:
|
Quote:
Originally posted by Kovacs
ls -R | wc -l
|
is there a better solution in stead of counting number of lines?
|
|
|
03-18-2004, 01:49 AM
|
#4
|
LQ Guru
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796
Rep:
|
maybe
Code:
find . -type f | wc -l
?
that doesnt count symbolic links though
|
|
|
03-18-2004, 01:56 AM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
None I know of in standard installations ... but you
can probaly write something in C.
Cheers,
Tink
|
|
|
03-25-2004, 01:48 PM
|
#6
|
LQ Newbie
Registered: Mar 2004
Posts: 1
Rep:
|
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!
|
|
|
03-25-2004, 01:53 PM
|
#7
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
? :)
Cheers,
Tink
|
|
|
All times are GMT -5. The time now is 05:17 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|