help!
How do I write Shell Script that counts the number of files in a directory then prints the number.
|
don't kow how to do a shell script but use this
c is lots faster name it count_files.c or whatever you want compile with gcc -o count_files count_files.c then put the executable in usr/bin or wherever you can also call this from a script of course count_files will get you the regular files in current working directory or you can put a path to a directory as an argument after the command if you want more than regular files counted change it or write back Code:
#include <dirent.h> |
Re: help!
Quote:
Code:
#!/bin/sh basically it lists all files in the current directory, then counts the lines that were listed... the SNIP is there cuz when you do a "ls -al" there's two lines that represent "./" and "../" and one line that represents the total size, so we subtract them... just my two cents... |
Use -A instead of -a and 1 instead of l
and forget about snip ;) Cheers, Tink |
Quote:
=) Code:
ls -A1 | wc -l |
/me takes a bow:"Pleasure, mate!" ;)
|
All times are GMT -5. The time now is 12:06 AM. |