Shell考题初级篇

将当前目录下大于10K的文件转移到/tmp目录下

find . -type f -size +10k -exec mv {} /tmp \;

编写一个shell,判断用户输入的文件是否是一个字符设备文件。如果是,请将其拷贝至/dev目录下

#!/bin/bash
read -t 30 -p 'Please output the file you specified:' str1
# 读取用户输入内容

if [ -n ${str1} ] && [ -e ${str1} ];
# 判断文件的真伪
  then
    str2=$(ls -l ${str1})
    str3=${str2:0:1}
    if [ $str3 == "c" ];
    # 判断文件是否是块设备
      then
    mv $str1 /dev/
    fi
  else
    echo "Input is wrong."
fi

请解释该脚本中注释行的默认含义与基础含义

#!/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代表停止的优先级。优先级数字越小表示越先被执行
第三行:告诉使用者脚本文件应存放路劲
第四行:告诉用户启动方式以及启动的用途
第五行:对于脚本服务的简单描述
第六行:文件的扩展可执行操作

写一个简单的shell添加10个用户,用户名以user开头

#!/bin/bash
for i in `seq 1 10`;
  do
    useradd user${i}
  done

写一个简单的shell删除10个用户,用户名以user开头

#!/bin/bash
for i in `seq 1 10`;
  do
    userdel -r user${i}
  done

写一个shell,在备份并压缩/etc目录的所有内容,存放在/tmp/目录里,且文件名如下形式yymmdd_etc.tar.gz

#!/bin/bash
NAME=$(date +%y%m%d)_etc.tar.gz
tar -zcf /tmp/${NAME} /etc

猜你喜欢

转载自www.cnblogs.com/guge-94/p/11540238.html
今日推荐