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

 

转载于:https://www.cnblogs.com/guge-94/p/11540238.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值