#!/bin/bash cd /var File=`ls /var` for i in *; do file_type=`ls -ld $i |cut -b1` case $file_type in d) echo "$i is 目录" ;; l) echo "$i is 链接文件" ;; -) echo "$i is 普通文件" ;; b) echo "$i is 设备文件" ;; c) echo "$i is 字符文件" ;; esac
done
2、添加10个用户user1-user10,密码为8位随机字符
#!/bin/bash for i in {1..10}; do id user$i &>/dev/null && echo "user$i is exit" || useradd user$i User_passwd=`echo $RANDOM |md5sum | cut -c 1-8` echo user$i:$User_passwd | chpasswd echo "user$i $User_passwd">>a.txt done bug 如果账户存在会将密码重置,建议增加一次判断,替换成 id user$i &>/dev/null && { echo "user$i is exit";continue; },不能使用(),()开启子