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

# 利⽤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博客

  • 9
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值