[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

shell command

Posted on 2011-09-23
5
Medium Priority
?
323 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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.
Suggested Courses

649 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