Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski 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
Jun 19, 2002
1
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.
 
Replies continue below

Recommended for you

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