我有一个bash脚本,递归打印文件的大小
for x in `ls $1`; do
if [[ -d $x ]]; then
echo "Going into $x"
bash `readlink -en $0` `readlink -en $x`
echo "Returning to parent"
elif [[ -f $x ]]; then
wc -c $x
elif [[ -h $x ]]; then
echo "Symbolic"
elif [[ -b $x ]]; then
echo "block-special"
elif [[ -c $x ]]; then
echo "character-special"
elif [[ -p $x ]]; then
echo "pipe"
elif [[ -S $x ]]; then
echo "socket"
else
echo Skipping $x
fi
done
但有些文件正在落入else语句。例如,
$ stat Desktop.tar.gz
File: 'Desktop.tar.gz'
Size: 1884 Blocks: 8 IO Block 4096 regular file
...
所以即使Desktop.tar.gz被标记为常规文件,它也不会被if [[ -f $x ]];
抓住......为什么会这样?它不仅仅是几个文件,它们 。
$ ls
backup csc Desktop etc forkres
IdeaProjects log ppid s3 Templates Videos
仓 csc.7z文件forkbomb forktime包括音乐ppid.c scratch timefork Brackets.Release.1.6.64-bit csc.tar.gz下载forkbomb.c fileSizes.sh lib图片公共分享timefork.c
$ bash fileSizes.sh .
Going into backup
Skipping backup.tar.gz
Skipping bin.tar.gz
Skipping Brackets.Release.1.6.64-bit.tar.gz
Skipping csc.7z.tar.gz
10151 csc.tar.gz
Skipping csc.tar.gz.tar.gz
Skipping Desktop.tar.gz
...
Skipping Videos.tar.gz
Returning to parent
Going into bin
Skipping drracket
Skipping gracket
Skipping gracket-text
...
Skipping unsplit
Returning to parent
Going into Brackets.Release.1.6.64-bit
Skipping control.tar.gz
...
Returning to parent
Going into csc
Skipping rootkey(1).csv
Skipping rootkey.csv
154 forkbomb.c
307200 forkres
8776 forktime
533 hw4_2.sh
Going into IdeaProjects
Skipping cscsh
Returning to parent
...
8768 ppid
524 ppid.c
8776 timefork
395 timefork.c
Going into Videos
Returning to parent
为了便于阅读,有些打印件未列出(...)。