Welcome, Guest. Please Login or Register
AIX User Group Forum
Dec 22nd, 2014, 7:24am
News: Welcome to the AIX User Group forum.
Home Help Search Login Register


Pages: 1
Send Topic Print
How to count dir files (Read 19 times)
shorti09
Freshman
*


AIX User Group
Rocks!

Posts: 1
How to count dir files
Dec 20th, 2010, 3:45pm
 
Hello, does anyone know of a command that will count the number of files in a directory on AIX 6.1 +.  I know I can opendir and readdir but was looking for a quick way to just count the files.

Thanks in advance
Back to top
 
 
  IP Logged
Tim
Sophomore
**


AIX User Group
Rocks!

Posts: 48
Re: How to count dir files
Reply #1 - Dec 21st, 2010, 9:43am
 
$ ls |wc -l
mind that you also have the links and directories in that case.

if you want only the files :
$ find . -type f|wc -l
-> this also includes subdirectories
Back to top
 
 
  IP Logged
Just Joat
Forum Moderator
*****


AIX User Group
Rules!

Posts: 109
Re: How to count dir files
Reply #2 - Dec 21st, 2010, 10:27am
 
I don't think there is a command to do that, but here's a script that
counts all the files in the current directory, excludes links and sub-directories...

typeset -i cnt=0
for x in $(ls);do
if [ -f $x ]; then
print $x
cnt=cnt+1
fi
done
print $cnt

Ksh test for file is -f in the above...
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print