将当前目录下大于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

 

批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串)

#!/bin/bash
for i in `seq 1 10`;
  do
    useradd oldboy${i}
    echo $RANDOM | md5sum | cut -c 1-8 | passwd --stdin oldboy${i}
  done

  

写一个脚本,实现判断192.168.10.0/24网络里,当前在线用户的IP有哪些(方法有很多)

#!/bin/bash
red="\e[31m"
shutdown="\e[0m"
green="\e[32m"
for((i=2;i<=254;i++))
do
  ping -c 1 -W1 -w 0.1 192.168.10.${i} &> /dev/null 
  if [ $? -eq 0 ]
   then
    echo -e "${green}"192.168.10.${i}${shutdown}" is running."
   else
    echo -e "${red}"192.168.10.${i}${shutdown}" is stop."
  fi
done
View Code

相关文章:

  • 2021-08-19
  • 2021-11-02
  • 2021-11-22
  • 2021-04-06
  • 2021-08-26
  • 2022-01-23
  • 2021-08-06
猜你喜欢
  • 2021-05-06
  • 2021-10-03
  • 2021-04-18
  • 2021-06-25
  • 2021-09-07
相关资源
相似解决方案