Linux实践——第七次实验课上机

答案仅供参考。作者水平有限,有错误之处欢迎指出。

1 在 exp4 目录下创建一个 shell 脚本 largest,要求如下:
(1) 屏幕显示 Please enter the first integer:▌然后接收用户的输入
(2) 屏幕显示 Please enter the second integer:▌然后接收用户的输入
(3) 屏幕显示 Please enter the third integer:▌然后接收用户的输入
(4) 之后,显示最大的整数。

#!/bin/bash
echo -n "Please enter the first integer:"
read a1
echo -n "Please enter the second integer:"
read a2
echo -n "Please enter the third integer:"
read a3
res=$a1
if [ $a2 -gt $res ]; then
		$res=$a2
fi
if [ $a3 -gt $res ]; then
		$res=$a3
fi
echo "$res"

2 在 exp4 目录下创建一个 shell 脚本 user_exist,要求如下:
(1) 屏幕显示 Please input a username:▌然后键盘输入一个用户名
(2) 如果该用户存在,回显[该用户名]'s shell is [该用户默认 shell]
(3) 如果不存在,回显[该用户名] not exists.

#!/bin/bash
echo -n "Please input a username:"
read name
egrep "\<$name\>" /etc/passwd >/dev/null
if [ $? -eq 0 ];then
		echo "${name}'s shell is /bin/bash"
else
		echo "$name not exists."
fi

3 在 exp4 目录下创建一个 shell 脚本 filecopy,要求如下:
(1) 判断 exp4 目录下是否存在目录 FILE3-5K,如果存在则先删除再新建,否则新建
(2) 将 exp4 目录下的 FILE3 目录内小于 5k 的文件复制到 FILE3-5K 目录内

#!/bin/bash

if [ -d ~/exp4/FILE3-5K ];then
		rm -rf ~/exp4/FILE3-5K
		mkdir ~/exp4/FILE3-5K
else
		mkdir ~/exp4/FILE3-5K
fi

find ~/exp4/FILE3/* -size -5k -exec cp {} ~/exp4/FILE3-5K \;

友情提示:5k不对的话,用6k

4 在 exp4 目录下创建一个 shell 脚本 exercise4,要求如下:
(3) 判断 exp4 目录下是否存在目录 FILE4,如果存在则先删除再新建,否则新建
(4) 在 FILE4 目录下,新建 100 个文件,文件名依次为 file001 至 file100
(5) 使用 tar 命令打包并压缩这 100 个文件为 allfile.tar.gz,将该文件移动到 exp4 目录下
(6) 查看 allfile.tar.gz 文件的权限,并将其权限修改为 user 可读可写可执行,group 可读,other 可读

#!/bin/bash

if [ -d ~/exp4/FILE4 ];then
		rm -rf ~/exp4/FILE4
		mkdir ~/exp4/FILE4
else
		mkdir ~/exp4/FILE4
fi

cd ~/exp4/FILE4
touch file{001..100}
tar -czf allfile.tar.gz *
mv -f ~/exp4/FILE4/allfile.tar.gz ~/exp4
cd ~/exp4
ls -l allfile.tar.gz
chmod u+rwx allfile.tar.gz
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值