当前位置:主页 > 查看内容

华南农业大学Linux课程实验二

发布时间:2021-05-28 00:00| 位朋友查看

简介:# 利?SSH客户端登录 root 账号查看 /tmp ?录下是否存在??录 myshare如果没有则建?该?录[rootwu1 ~]# mkdir /tmp/myshare# 在 myshare ?录下创建?个名为“学号”的?件夹和?个名为 exam2.txt 的?件[rootwu1 ~]# mkdir /tmp/myshare/201814090518[rootwu1 ~]# t……
# 利?SSH客户端登录 root 账号,查看 /tmp ?录下是否存在??录 myshare,如果没有则建?该?录;
[root@wu1 ~]# mkdir /tmp/myshare

# 在 myshare ?录下创建?个名为“学号”的?件夹和?个名为 exam2.txt 的?件;
[root@wu1 ~]# mkdir /tmp/myshare/201814090518
[root@wu1 ~]# touch /tmp/myshare/201814090518/exam2.txt

# 创建?个名字为 test 的新?户,并指定uid为1024;
[root@wu1 ~]# useradd -u 1024 test

# 把 /etc/passwd 和 /etc/shadow 含有?户 test 信息的 ? 追加到 exam2.txt ?件中;
[root@wu1 ~]# cat /etc/passwd |grep test >> /tmp/myshare/201814090518/exam2.txt
[root@wu1 ~]# cat /etc/shadow |grep test >> /tmp/myshare/201814090518/exam2.txt

# 把 /etc/passwd 前13?的内容 追加到 myshare ?录下 名为 exam2.txt 的?件中;
[root@wu1 ~]# head -n 13 /etc/passwd >> /tmp/myshare/201814090518/exam2.txt

# 把 myshare ?录下的所有?件和??录的内容以?格式的?式追加到 exam2.txt 中;
[root@wu1 ~]# ls -lR /tmp/myshare >> /tmp/myshare/201814090518/exam2.txt

# 把 myshare ?录及其?录下的所有?件和??录的拥有者设置为?户 test ,组改为mail;
[root@wu1 ~]# chown -R test /tmp/myshare
[root@wu1 ~]# chgrp -R mail /tmp/myshare

# 把 myshare ?录下的所有?件和??录的内容以?格式的?式追加到 exam2.txt 中;
[root@wu1 ~]# ls -lR /tmp/myshare >> /tmp/myshare/201814090518/exam2.txt

# 利?su命令切换到?户 test 账号;
[root@wu1 ~]# su test

# 进?/tmp/myshare/“学号”?录,采?vi编辑器编写以下程序,程序名称为hello.sh
[test@wu1 root]$ vi /tmp/myshare/201814090518/hello.sh

# 保存 hello.sh 后,给予 hello.sh 拥有者可读、可写和可执?的权限,同组可读可执?,其他?可执?权限;
[test@wu1 root]$ chmod 751 /tmp/myshare/201814090518/hello.sh

# 以?格式的形式查看 hello.sh 的?件权限信息,并把输出内容追加到 exam2.txt;
[test@wu1 root]$ ll /tmp/myshare/201814090518/hello.sh >> /tmp/myshare/201814090518/exam2.txt

# 输? ./hello.sh 执?脚本,查看输出结果。并把输出结果追加 exam2.txt;
[test@wu1 root]$ /tmp/myshare/201814090518/hello.sh >> /tmp/myshare/201814090518/exam2.txt

# 进??户 test 的?户主?录,在这个?录下创建 hello.sh 的软链接myhello.sh,同时拷? hello.sh 到该?录下并改名为 hello.sh.bak;
[test@wu1 root]$ cd /home/test
[test@wu1 ~]$ ln -s /tmp/myshare/201814090518/hello.sh /home/test/myhello.sh
[test@wu1 ~]$ cp /tmp/myshare/201814090518/hello.sh /home/test/hello.sh.bak

# 以?格式形式查看?户 test 主?录下的所有?件并把结果追加到 exam2.txt中;
[test@wu1 ~]$ ls -lR /home/test >> /tmp/myshare/201814090518/exam2.txt

# 执??户 test 主?录下的myhello.sh?件,查看链接是否正常;
[test@wu1 ~]$ /home/test/myhello.sh

# 退出?户 test 帐号,回到root帐号
[test@wu1 ~]$ su root

# 以?格式形式查看?户 test 主?录下的所有?件(含隐藏?件)并把结果追加到 exam2.txt中;
[root@wu1 test]# ls -lRa /home/test >> /tmp/myshare/201814090518/exam2.txt

# 从 /usr 开始查找后缀名为.conf的所有?件(普通?件),把输出结果追加到 exam2.txt中;
[root@wu1 test]# find /usr -name "*.conf" -type f  >> /tmp/myshare/201814090518/exam2.txt

# 从上?步找到的conf?件中找出?件容量最?的?件,并把这个?件以?格式形式追加到exam2.txt 中 ;(倒引号)
[root@wu1 ~]# ls -lSh `find /usr -name "*.conf" -type f` | head -n 1 >> /tmp/myshare/201814090518/exam2.txt

# 统计出系统中有多少个?户帐号,把数量追加到 exam2.txt 中;
[root@wu1 ~]# cat /etc/passwd | wc -l >> /tmp/myshare/201814090518/exam2.txt

# 把 exam2.txt ?件转换为windows格式。
[root@wu1 ~]# unix2dos /tmp/myshare/201814090518/exam2.txt

# 删除?户test 的所有内容(包括主?录)
[root@wu1 ~]# userdel -r test

# 删除/tmp/myshare?录
[root@wu1 ~]# rm -rf /tmp/myshare

参考

Linux——两种方式查找指定后缀的文件并输出容量最大的文件_JiaM-CSDN博客

;原文链接:https://blog.csdn.net/wpw2000/article/details/115538871
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐