Home

zhangyiqun

Thoughts, stories and ideas.

Notes Blog Archives About
12 Mar 2009

统计/dev下各类型文件的总数

朋友遇到的面试题,我是用awk来写,纯体力劳动的活。他的解法我脑袋里没印象,因为wc几乎没碰过……看来在shell这块还要多多努力

#!/bin/bash

bb=`ls -l /dev | grep ^b | wc -l`

cc=`ls -l /dev | grep ^c | wc -l`

pp=`ls -l /dev | grep ^p | wc -l`

ll=`ls -l /dev | grep ^l | wc -l`

ss=`ls -l /dev | grep ^s | wc -l`

echo “Count: $[$bb+$cc+$pp+$ll+$ss]”

Notes Blog Archives About