# 通过指令获取用户根目录中内容详细信息的第一列数据 cd ~ result=`ls -lh | awk '{print $1}'` # 遍历获取到指令结果的每一行内容 f_count=0 d_count=0 l_count=0 for x in $result do ft=${x:0:1} if [ $ft = "-" ] then f_count=`expr $f_count + 1` elif [ $ft = 'd' ] then d_count=`expr $d_count + 1` elif [ $ft = 'l' ] then l_count=`expr $l_count + 1` fi done echo 用户根目录下的内容清单: >> ~/清单.txt echo "文件数量:${f_count}" >> ~/清单.txt echo "文件夹数量:${d_count}" >> ~/清单.txt echo "软连接数量:${l_count}" >> ~/清单.txt
10.shell编程练习
本节511字2025-03-13 18:41:15