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 JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple list with number of files

Status
Not open for further replies.

bonehead

Computer
Joined
Jun 19, 2002
Messages
1
Location
US
How do you get the number of files within a directory and it's sub-directories in Unix? I'm new to this and have no idea.
 
This can be written more concisely, but I left exploded for clarity.

Code:
prompt>ls -lR |grep -v ^'./' |grep -v ^total|grep -v ^d|grep -v ^$|wc -l

This recursively lists the contents of directories, then, using 'grep -v', discards lines starting with './' and 'total' and 'd' and empty lines. The results are piped through 'wc' to get the number of lines remaining.

Oh yeh... this is on Solaris. Maybe slightly different for Linux or HP-UX or other, but probably not.

'hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top