ls command for listing the number of files | 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 !!

ls command for listing the number of files

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-23-2007
jimmyc jimmyc is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 30 September 2008, 6:23 PM EDT
Location: dallas tx
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ls command for listing the number of files

I've searched the man page for an option for the ls command to print the number of files in a directory. I'm moving files and folders around and thought a count of files would be a quick way to determine if I was missed one somewhere. Some "unix's" shells do this I think... maybe linux...

Anybody know how to do this real quick

System is: SunOS 5.10 Generic sun4u sparc SUNW,Ultra-5_10 KSH

I did this but is comes back with byte count rather than a file count.
ls -l |wc


Thanks All )
Sponsored Links
    #2  
Old 03-23-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 21 September 2014, 9:20 PM EDT
Location: NM
Posts: 10,211
Thanks: 278
Thanked 796 Times in 743 Posts
ls -l | wc -l
Sponsored Links
    #3  
Old 03-23-2007
jimmyc jimmyc is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 30 September 2008, 6:23 PM EDT
Location: dallas tx
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Dang.... I knew I was close...

Thx Jim
    #4  
Old 03-23-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 17 Times in 17 Posts
one little minor problem, at least what i have encountered, is that ls -l list out the files, including the "total" line on the very first line. wc -l will count that line too. So its just sufficient to exclude the switch , or use ls -1 instead.
Sponsored Links
    #5  
Old 03-24-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 31 August 2014, 7:32 PM EDT
Location: Toronto, Canada
Posts: 2,877
Thanks: 0
Thanked 110 Times in 102 Posts
Quote:
Originally Posted by jimmyc
I've searched the man page for an option for the ls command to print the number of files in a directory. I'm moving files and folders around and thought a count of files would be a quick way to determine if I was missed one somewhere. Some "unix's" shells do this I think... maybe linux...

Anybody know how to do this real quick

System is: SunOS 5.10 Generic sun4u sparc SUNW,Ultra-5_10 KSH

I did this but is comes back with byte count rather than a file count.
ls -l |wc

You can add the -l option to wc, or you can do it in the shell itself, which will be much faster:

Code:
set -- *
echo $#

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
command to verify number of files Mr.AIX AIX 3 02-15-2011 09:36 AM
Long listing of files using find command on remote server via SSH atukuri UNIX for Dummies Questions & Answers 2 04-20-2010 01:13 PM
find command -- listing files twice Straitsfan UNIX for Dummies Questions & Answers 2 01-11-2010 01:23 AM
TAR command , listing backed up files FredSmith Solaris 3 10-03-2005 10:08 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 10:52 AM



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