Solved

shell command

Posted on 2011-09-23
5
314 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

911 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

20 Experts available now in Live!

Get 1:1 Help Now