Solved

shell command

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

776 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