Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

ls command for listing the number of files

UNIX for Dummies Questions & Answers


 
 
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 Linux)
Sponsored Links
    #2  
Old Unix and Linux 03-23-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 23 July 2016, 12:12 AM EDT
Location: NM
Posts: 10,775
Thanks: 428
Thanked 950 Times in 882 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: 11 July 2016, 2:55 PM EDT
Location: Toronto, Canada
Posts: 2,898
Thanks: 0
Thanked 134 Times in 118 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
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 05:10 AM.