• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

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?
0
nobleit
Asked:
nobleit
1 Solution
 
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
 
AnacreoCommented:
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now