unix command to cound the number of files in a folder | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

unix command to cound the number of files in a folder

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-11-2008
manas6 manas6 is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 27 January 2010, 12:53 AM EST
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
unix command to cound the number of files in a folder

Hi All

Can some one help me out.

Please tell the unix command to cound the number of files in a folder.

Ungent please#

Thanks manas
Sponsored Links
    #2  
Old 04-11-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
 
Join Date: Jul 2006
Last Activity: 22 September 2014, 2:05 AM EDT
Location: Berlin, Germany
Posts: 5,400
Thanks: 54
Thanked 230 Times in 223 Posts

Code:
ls | wc -l

Sponsored Links
    #3  
Old 04-11-2008
manas6 manas6 is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 27 January 2010, 12:53 AM EST
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Duke

Thanks for the information its working.

I have one more clarification.

if I have a directory among the files and that particular directory have some more files. What to do in this regard.

I have tried with ls -R| wc -l
but it is giving the working count. Giving one extra couont.
Thanks in advance

Last edited by manas6; 04-11-2008 at 06:52 AM.. Reason: misstyped
    #4  
Old 04-11-2008
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 30 June 2014, 4:32 AM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts
If your folder has directories and files, and you want to count only files, use the below.

Code:
ls -l | grep ^[^d] | wc -l

i.e., listing objects which are not directories, and counting them.
Sponsored Links
    #5  
Old 04-11-2008
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 30 June 2014, 4:32 AM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts
Quote:
Originally Posted by manas6 View Post
Hi Duke

Thanks for the information its working.

I have one more clarification.

if I have a directory among the files and that particular directory have some more files. What to do in this regard.

I have tried with ls -R| wc -l
but it is giving the working count. Giving one extra couont.
Thanks in advance
In that case, use this command

Code:
find ./ -type f | wc -l

It will find all files recursively and count them.
Sponsored Links
    #6  
Old 04-11-2008
manas6 manas6 is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 27 January 2010, 12:53 AM EST
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Hi krish

find ./ -type f | wc -l this is working fine

Thanks for the information

Regards
Manas
Sponsored Links
    #7  
Old 04-21-2008
palash2k palash2k is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 31 August 2010, 3:20 AM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
count number of files in a folder

If you want to count the number if files in a folder, assume it is your present working directory then you try this

ls -F | grep -v -e "/" -e "@" | wc -w

this will show you number of files but not any directory or link count.

If you would like to list out number of all the objects excluding directory then use

ls -F | grep -v "/" | wc -w
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Move Files From One Folder To Another In UNIX Jassz UNIX and Linux Applications 1 03-02-2011 12:06 AM
Unix command to count the number of files with specific characters in name murphysm UNIX for Dummies Questions & Answers 6 05-07-2010 04:12 AM
UNIX: Command to compress folder and all files into a tar kane4355 UNIX for Advanced & Expert Users 7 01-25-2010 03:29 AM
How to learn the number of files under a particular folder, containing subfolders cy163 UNIX for Dummies Questions & Answers 5 09-01-2007 10:55 AM
unix C++: get the files from a folder nadiamihu Programming 2 11-29-2006 04:23 AM



All times are GMT -4. The time now is 02:13 AM.