Solved

shell command

Posted on 2011-09-23
5
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 21

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

733 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