
目录
1.若下达 # rmdir test 命令来删除某个已存在的目录,但无法成功,请说明可能的原因
6.假设你是系统管理员,需要增加一个新的用户账号thyl,为新用户设置初始密码,然后创建一个新组test,把用户thyl加入到新建的组test中
7.在目录/root/zheng下,新建一个目录back,然后将该目录改名为bak,在bak下建立两个长度为“0”的文件test1和test2,然后把test2复制到其父目录中并改名为file2
8.简述用两种方法运行shell的脚本文件/home/test/test.sh
9.编写个shell脚本将当前目录下大于10K的文件转移到/tmp目录下
10.用Shell编程,判断一文件是不是字符设备文件,如果是将其拷贝到 /dev 目录下。要求必须有提示信息:input file name:
11.使用for循环输出当前文件夹下面的所有文件,统计文件数量并打印

文件夹不为空 或者 文件夹没有删除权限
代码
- #!/bin/bash
- s=0
- i=1
- while ((i<=100))
- do
- s=$(($s+$i))
- ((i++))
- done
- echo $s

1.bash 或sh 来执行bash shell脚本

2.设置可执行权限

代码
- #!/bin/bash
- for((i=1;i<=100;i=i+1))
- do
- echo "$i"
- done


代码
- #!/bin/bash
- i=1
- while((i<=100))
- do
- echo "$i"
- ((i++))
- done
执行结果

代码
- #!/bin/bash
- read -p "the first:" a
- read -p "the second:" b
- echo "$(($a+$b))"
-p 后面跟提示信息,即在输入前打印提示信息
执行结果

代码
- #!/bin/bash
- useradd thyl
- passwd thyl
- groupadd test
- usermod -g test thyl
- #!/bin/bash
- cd /root/thyl
- mkdir back
- mv back bak
- touch test1
- touch test2
- cp test2 ../file2
第一种方法:
bash /home/test/test/.sh
第二种方法:
- chmod 777 /home/test/test.sh
-
- ./test.sh
- #!/bin/bash
- for FileName in `ls -l | awk '$5>10240 {print $9}'`
- do
- mv $FileName /tmp
- done
代码
- #!/bin/bash
- FILENAME= echo "Input file name:"
- read FILENAME
- if [ -c $FILENAME ]
- then
- cp $FILENAME /dev
- else
- echo "这不是设备文件"
- fi
代码
- #!/bin/bash
- num=0
- for i in $(ls)
- do
- num=$[$num+1]
- echo "item:$i"
- done
- echo "the number of files is $num"
执行结果
