Solved

shell command

Posted on 2011-09-23
5
310 Views
Last Modified: 2012-06-27
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
Comment
Question by:nobleit
5 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 36589426
Assuming you mean "real" files, not directories, links etc...
ls -la |grep  "^-" |wc -l
0
 
LVL 48

Expert Comment

by:Tintin
ID: 36589891

Shorter to do

ls -aF | grep -vc /

Open in new window

0
 
LVL 5

Expert Comment

by:hossamshaaban
ID: 36592060
ls -la | grep -c '^-'
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 36597536
if you want to count the subdirectory files also, then

find . -type f | wc -l

Open in new window

0
 
LVL 4

Accepted Solution

by:
Anacreo earned 500 total points
ID: 36912760
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now