1、将当前目录下大于10K的文件转移到/tmp目录下
find . -size +10 -exec mv {} /tmp \;
2、编写一个shell,判断用户输入的文件是否是一个字符设备文件。如果是,请将其拷贝至/dev目录下
#!/bin/bash read -p 'Please input file name: ' Filename if [ -c "$Filename" ] then mv $Filename /dev/ fi
3、请解释该脚本中注释行的默认含义与基础含义
#!/bin/sh # chkconfig: 2345 20 80 # /etc/rc.d/rc.httpd # Start/stop/restart the Apache web server. # To make Apache start automatically at boot, make this # file executable: chmod 755 /etc/rc.d/rc.httpd case "$1" in 'start') /usr/sbin/apachectl start ;; 'stop') /usr/sbin/apachectl stop ;; 'restart') /usr/sbin/apachectl restart ;; *) echo "usage $0 start|stop|restart" ;; esac
- 请解释该脚本中注释行的默认含义与基础含义
- 第一行:指定脚本文件的解释器
- 第二行:指定脚本文件在chkconfig程序中的运行级别,2345代表具体用户模式启动(可用'-'代替),20表示启动的优先级,80代表停止的优先级。优先级数字越小表示越先被执行
- 第三行:告诉使用者脚本文件应存放路劲
- 第四行:告诉用户启动方式以及启动的用途
- 第五行:对于脚本服务的简单描述
4、写一个简单的shell添加10个用户,用户名以user开头
#!/bin/bash for i in {1..10} do useradd user$i done
5、写一个简单的shell删除10个用户,用户名以user开头
#!/bin/bash for i in {1..10} do userdel -r user$i done
6、写一个shell,在备份并压缩/etc目录的所有内容,存放在/tmp/目录里,且文件名如下形式yymmdd_etc.tar.gz
#!/bin/bash NAME=$(date +%y%m%d)_etc.tar.gz tar -zcf /tmp/${NAME} /etc