ls command for listing the number of files | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix or Linux Image)
Sponsored Links
    #2  
Old Unix and Linux 03-23-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 27 March 2015, 11:26 AM EDT
Location: NM
Posts: 10,408
Thanks: 325
Thanked 854 Times in 793 Posts
ls -l | wc -l
Sponsored Links
    #3  
Old Unix and Linux 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 Unix and Linux 03-23-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 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 Unix and Linux 03-24-2007
cfajohnson's Unix or Linux Image
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 5 March 2015, 8:48 PM EST
Location: Toronto, Canada
Posts: 2,882
Thanks: 0
Thanked 116 Times in 105 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 01:14 AM.