某校linux课实验(一)

0x00

某老师linux课的实验题,结果发现自己用了这些年linux还是对find、sort不太熟悉,还有awk,觉得不应该沉溺于ubuntu之类的图形界面之中,切切实实地用shell command来用linux才是正道。实验使用Centos6.4 minimal……

P.S.所以所有linux实验都只会会在这两个系列的部分社区发行版进行。如:ubuntu,debian,centos6,rhel5。默认环境Centos minimal(300来m镜像)

0x01

1.root帐号登录,查看/tmp目录,如果/tmp目录下没有子目录myshare,则建立该目录。

 # touch /tmp/myshare 
  # mkdir /tmp/myshare 无法覆盖,应该与 rm -rf /tmp/myshare 一起用

2.创建帐号testuser。

  # useradd testuser  
    # passwd testuser   密码是:fuckwindows

3.把myshare目录及其目录下的所有文件和子目录的拥有者该为testuser,工作组改为users。

    # chown -R testuser:users /tmp/myshare



4、切换至testuser帐号。进入/tmp/myshare目录,采用vim编辑器编写以上程序,程序名称为hello.sh:
#!/bin/bash
echo "app start"
echo -e
func (){
  echo "hello world!"
}
func
echo -e
echo "app end"


 # su testuser  		
 # vi /tmp/myshare/hello.s 


5.保存hello.sh后,给予hello.sh拥有者可读、可写和可执行的权限,同组可读可执行,其他人可执行权限。
  
  $ chmod 751 hello.sh 

6.输入./hello.sh,观察程序输出的效果。

  $ ./hello.sh


7.进入testuser的用户主目录,在这个目录下创建hello.sh的软链接,同时拷贝hello.sh到该目录下并改名为hello.sh.bak,要求拷贝时保留文件属性值。

  $ ln -s /tmp/myshare/hello.sh	
     $cp -p /tmp/myshare/hello.sh ./hello.sh.bak


8.退出testuser帐号,回到root帐号,从/开始查找后缀名为.conf的所有文件,把输出结果重定向到testuser帐号的主目录下的output.txt文件。

  $ su root		
    # find / -name "*.conf" >output.txt

9.在上一步操作的.conf文件中找出文件容量最大的和最小那个,并把这两个文件的容量大小输出到output.txt文件中。

    # find / -name "*.conf" -exec ls -l {} \;|cut -d' ' -f5|sort -n|head -1
  # find / -name "*.conf" -exec ls -l {} \;|cut -d' ' -f5|sort -nr|head -1


10.统计出系统中有多少个用户帐号,把数量输出到output.txt文件中。

  # cat /etc/passwd|cut -d: -f1|wc -l>>output.txt

11.把output.txt文件转换为windows记事本可正规打开的格式。
  这里比较坑爹,装unix2dos不行,然后就转为tr了,理解一下mac,win,unix的文件格式就知道 \r \r\n \n,那用tr好了

  # tr '\n' '\r\n' <output.txt> output1.txt 前面的是unix文件

12.tar打包压缩testuser帐号主目录下的所有文件。 

   # tar -zcvf ./testuser.tar.gz /home/testuser


13.用U盘把上一步打包压缩文件拷贝到U盘上。
  #fdisk -l	找到u盘
  # mkdir /mnt/udisk&&mount -t vfat /dev/sdb1 /mnt/udisk
  # cp testuser.tar.gz /mnt/udisk
  # umount /mnt/udisk


14、执行userdel -r testuser,执行rm -fr myshare



0x03 后续:

很多人发现第九题的用不了,多数是rhel5.x系列的,补充一下

# find / -name "*.conf" -exec ls -l {} \;|sort -t' ' -k5 -n|cut -d' ' -f5|head -1
# find / -name "*.conf" -exec ls -l {} \;|sort -t' ' -k5 -nr|cut -d' ' -f5|head -1

如果先用cut再用sort,会发现有三行为空,是因为cut有个很严重的缺陷,在处理多个空格时候会非常麻烦



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1 root帐号登录 查看 tmp目录 如果 tmp目录下没有子目录myshare 则建立该目录 2 创建帐号testuser 3 把myshare目录及其目录下的所有文件和子目录的拥有者该为testuser 工作组改为users 4 切换至testuser帐号 进入 tmp myshare目录 采用vim编辑编写以上程序 程序称为hello sh: # bin bash echo "app start" echo e func { echo "hello world " } func echo e echo "app end" 5 保存hello sh后 给予hello sh拥有者可读 可写和可执行的权限 同组可读可执行 其他人可执行权限 6 输入 hello sh 观察程序输出的效果 7 进入testuser的用户主目录 在这个目录下创建hello sh的软链接 同时拷贝hello sh到该目录下并改为hello sh bak 要求拷贝时保留文件属性值 8 退出testuser帐号 回到root帐号 从 开始查找后缀为 conf的所有文件 把输出结果重定向到testuser帐号的主目录下的output txt文件 9 在上一步操作的 conf文件中找出文件容量最大的和最小那个 并把这两个文件的容量大小输出到output txt文件中 10 统计出系统中有多少个用户帐号 把数量输出到output txt文件中 11 把output txt文件转换为windows记事本可正规打开的格式 12 tar打包压缩testuser帐号主目录下的所有文件 13 用U盘把上一步打包压缩文件拷贝到U盘上 14 执行userdel r testuser 执行rm fr myshare">1 root帐号登录 查看 tmp目录 如果 tmp目录下没有子目录myshare 则建立该目录 2 创建帐号testuser 3 把myshare目录及其目录下的所有文件和子目录的拥有者该为testuser 工作组改为users 4 切换至testuser帐号 进入 tmp myshare [更多]
1、root帐号登录,查看/tmp目录,如果/tmp目录下没有子目录myshare,则建立该目录。 2、创建帐号testuser。 3、把myshare目录及其目录下的所有文件和子目录的拥有者该为testuser,工作组改为users。 4、切换至testuser帐号。进入/tmp/myshare目录,采用vim编辑编写以上程序,程序称为hello.sh: #!/bin/bash echo "app start" echo -e func (){ echo "hello world!" } func echo -e echo "app end" 5、保存hello.sh后,给予hello.sh拥有者可读、可写和可执行的权限,同组可读可执行,其他人可执行权限。 6、输入./hello.sh,观察程序输出的效果。 7、进入testuser的用户主目录,在这个目录下创建hello.sh的软链接,同时拷贝hello.sh到该目录下并改为hello.sh.bak,要求拷贝时保留文件属性值。 8、退出testuser帐号,回到root帐号,从/开始查找后缀为.conf的所有文件,把输出结果重定向到testuser帐号的主目录下的output.txt文件。 9、在上一步操作的.conf文件中找出文件容量最大的和最小那个,并把这两个文件的容量大小输出到output.txt文件中。 10、统计出系统中有多少个用户帐号,把数量输出到output.txt文件中。 11、把output.txt文件转换为windows记事本可正规打开的格式。 12、tar打包压缩testuser帐号主目录下的所有文件。 13、用U盘把上一步打包压缩文件拷贝到U盘上。 14、执行userdel -r testuser,执行rm -fr myshare
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值