shell面试题

回复 收藏

shell3.jpg

shell4.jpg

2017-07-07 10:14 举报
已邀请:
0

LINUX_A - 不要在最能吃苦的年龄选择安逸!

赞同来自:

1.

#! /bin/bash

##find all of folders which beging with ms
##written by zhdya_20171011

find /tmp/msxf -name "ms*" > /tmp/dirlist.txt

for i in `cat /tmp/dirlist.txt`
do
        cd $i
        touch test.txt
done

2.

#! /bin/bash

##check a file which is c file or not
##written by zhdya_20171011

read -p "pls input a location,like "/tmp/":" l

cd $l
for i in `ls`
do
        if [ -c $i ]
        then
                cp $i /dev/
        fi
done

3.

#! /bin/bash

##add a new user group, and let all of new user join in.
##written by zhdya_20171011

read -p "pls input a user's group name, like msxf:" g
read -p "pls input a number which from XX and end of XX, like 01 05, it will create msfinance01 ... msfinance05:" n m

if [ -z $g ] && [ -z $n ] && [ -z $m ]
then
        echo "pls it must input the PARA."
        exit
fi

groupadd $g

echo "already created the usergroup $g"

for i in `seq $n $m`
do
        useradd msfinance$i -g $g
done

echo "already created the user you needs."

5.

#! /bin/bash

##backup all of file and folders in etc. and move to suitable place.
##written by zhdya_20170921

DATE=`date +%Y%m%d`
cd /
tar czvf $DATE_etc.tar.gz etc >/dev/null 2>&1
mv $DATE_etc.tar.gz /root/bak/
echo "already done, pls check it."

再次搞个任务计划即可!
crontab -e

0 0 1 * * /bin/bash /usr/local/sbin/baketc.sh

0

小熊

赞同来自:

第二题要加一个-a ,我执行了-a 就可以

#! /bin/bash##check a file which is c file or not##written by zhdya_20171011read -p "pls input a location,like "/tmp/":" lcd $lfor i in `ls`do        if [ -c $i ]        then                cp  -a $i /dev/        fidone

0

笨笨老男孩

赞同来自:

find /msxf/ms* -type d > dirlist.txt

for file in ` cut -d  -f 1 $ dirlist.txt`

do 

cd $file

touch test.txt

done

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: