The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
row count of all files with more than 0 byte sri2005 UNIX for Dummies Questions & Answers 6 04-29-2008 05:39 PM
Display the count of files wayne1411 Shell Programming and Scripting 4 01-09-2008 10:09 PM
Provide a count of files keymind UNIX for Dummies Questions & Answers 5 12-30-2007 01:57 PM
How to find the count of files in a directory sish78 UNIX for Dummies Questions & Answers 5 02-01-2007 03:58 PM
command to count files in dir balireddy_77 Shell Programming and Scripting 4 11-15-2006 01:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2006
mahalakshmi mahalakshmi is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 38
count of files

How to count the number of files in a directory.

Thanks
Mahalakshmi.A
  #2 (permalink)  
Old 11-28-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
I think this had been answered many times

only the count of files and not directories
Code:
ls -l | grep -c ^-
  #3 (permalink)  
Old 11-28-2006
sparcguy sparcguy is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Posts: 315
not sure if this is efficient tho

ls -l | grep -v drw | awk '{ print $9 }' | wc -l
  #4 (permalink)  
Old 11-28-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
you are assuming r and w perm for users if its a directory,
there need not be such a perm for user.

it could be even dr-x

in that case, your condition would fail to filter
  #5 (permalink)  
Old 11-28-2006
mahalakshmi mahalakshmi is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 38
Thanks for the replies which I had got.
Can you please explain me about awk '{print $9}' in ls -l | grep -v drw | awk '{ print $9 }' | wc -l

Thanks
Maha
  #6 (permalink)  
Old 11-28-2006
sparcguy sparcguy is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Posts: 315
hi,

grep -v use filter off anything that starts with drw like directories generally start with drw

wc is word count, -l used to display number of lines

awk '{ print $9 }' prints out the 9th column of the output

when you do a ls -l it prints out some file with

col1 col2 col3 col4 col5 col6 col7 col8 col9
-rw-r--r-- 1 root other 151 Nov 15 14:28 xx
drw-r--r-- 1 oracle dba 72 Nov 15 14:36 apple

enjoy
  #7 (permalink)  
Old 11-28-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
Code:
ls -l | grep -v drw | awk '{ print $9 }'
above command shows the 9th column of the grep o/p.

ex:

suppose o/p of the above grep command
Code:
-rwxr-xr-x    1 sri    sri         317 Sep 20 16:18 get1
then o/p of awk command would be

Code:
get1
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0