1.
#!/bin/bash
#name :Dave namespace:whoami 目的:作业
echo "hello `whoami`"
echo "`hostname`"
echo "`ls -l ../`"
echo $PATH
echo $HOME
echo "`df -h`"
echo "`id -g`"
echo "Good bye"
2.
i
id -g
dir=$(cd &(dirname $0) && pwd)
echo $dir
3.
#!/bin/bash
etc_count=`(ls -l /etc | grep "^d" | wc -l)`
etc_count2=`(ls -l /etc |grep "^-" | wc -l)`
var_count=`(ls -l /var | grep "^d" | wc -l)`
var_count2=`(ls -l /var | grep "^-" | wc -l)`
usr_count=`(ls -l /usr | grep "^d" | wc -l)`
usr_count2=`(ls -l /usr | grep "^-" | wc -l)`
echo "/etc一级子目录$etc_count个,文件$etc_count2个"
echo "/var一级子目录$var_count个,文件$var_count2个"
echo "/usr一级子目录$usr_count个,文件$usr_count2个"
4.
#!/bin/bash
ls /etc | grep "^p" -i |wc -l
5
#!/bin/bash
read -p "输入一个文件名" filename
var=(`ls -l $filename`)
num=`expr index $var "-"`
if [ $num -eq 1 ]
then
echo "文件为普通文件"
else
echo "不是普通文件"
fi