Shell Scripts: using wc and grep and awk
1. count the code lines using wc.
1: wc -l `find . -name *.c`
2. count the code lines, using an elegant way "xargs" to transfer the arguments of wc
1: find . -name *.c |xargs wc -l
3. count the code lines, self calculation the result of wc using awk
1: find . -name *.c |xargs wc -l|awk '
2: BEGIN {sum=0;fnum=0;}
3: {sum=sum+$1; printf "%-10s %s\n",$1,$2; fnum=fnum+1; }
4: END {printf "Total files: %s,\tTotal lines: %s.\n",fnum,sum}
5: '
4. List all the text files residing in current directory, recursively,
[code='c']
grep -rIc “.*” . | awk -F : ‘{if($2!=0)print($1)}’
[/code]
Here, -I let grep only search text files, -c count the line of files. When the count is larger than 0, we print it out.

cool code , i usual use the second way
“grep -I” for determining whether it’s a text file is a little ugly, is there a more elegant way to determine whether a file is text or not?