shell command

Is there any way to get the  set of shell commands that will give you the number of files in a directory in hp unix?
nobleitAsked:
Who is Participating?
 
AnacreoConnect With a Mentor Commented:
Files/Directories/etc:
$ ls -F | wc -l
101

Non Directories:
$ ls -F | grep -v '/$'| wc -l
78

Directories
$ ls -F | grep '/$' | wc -l
23

This has the benefit of not requiring lookups for extended meta info which could wake a hard drive or have a long return time on optical media.

To get the file count into a variable in sh/ksh/bash:
count=`ls -F | grep -v '/$' | wc -l`

Happy Hunting!
0
 
tfewsterCommented:
Assuming you mean "real" files, not directories, links etc...
ls -la |grep  "^-" |wc -l
0
 
TintinCommented:

Shorter to do

ls -aF | grep -vc /

Open in new window

0
 
hossamshaabanCommented:
ls -la | grep -c '^-'
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
if you want to count the subdirectory files also, then

find . -type f | wc -l

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.