Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number of files in a directory 1

Status
Not open for further replies.

unixwhoopie

Programmer
May 6, 2003
45
US
How do I get the number of files in a directory? I want to delete files in a directory but before that I need to make sure there are files.

Thanks
 
If you want to eliminate directories from the count.


ls -al |grep ^[^d] | wc -l
 
The most correct solution for you is,

find /your/path -type f | wc -l

find will use the -type option and display only files, no dirs, or other odd/special items, then and only then can you get an accurate count of files.. ls -la and other options will display "other" items in the output..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top