马哥教育网络班22期+第六周课程练习

1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;

]# cp -v  /etc/rc.d/rc.sysinit /tmp/
   `/etc/rc.d/rc.sysinit' -> `/tmp/rc.sysinit'
]# sed 's@^[[:space:]]\+@#@g' /tmp/rc.sysinit

2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符;

]# cp -v /boot/grub/grub.conf /tmp/
]# sed 's/^[[:space:]]\+//g' grub.conf

3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符

]# sed -n '/^#[[:space:]]\+/p' rc.sysinit 
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
# Load other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
# Sync waiting for storage.
# Device mapper & related initialization
# Start any MD RAID arrays that haven't been started yet
# Remount the root filesystem read-write.
# Clean up SELinux labels
# If relabeling, relabel mount points.
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
...
]# sed  '/^#[[:space:]]\+/d' /tmp/rc.sysinit

4、为/tmp/grub.conf文件中前三行的行首加#号;

]# sed '1,3s@^.*@#@g' /tmp/grub.conf 
#
#
#
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
   root (hd0,0)
   kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
   initrd /initramfs-2.6.32-431.el6.x86_64.img

5、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;

]# sed 's@\([enabled|gpgcheck]\)=0@\1=1@g' /etc/yum.repos.d/centos.repo 

6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201504020202

]# crontab -l
0 */4 * * *  /bin/cp -a /etc /backup/etc-$(date "+%Y%m%d%H%M") &>/dev/null

7、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20150402

]# crontab -l
0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-$(date "+%Y%m%d)" &>/dev/null

8、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中

]# crontab -l
0 */2 * * * grep "^S" /proc/meminfo >>/stats/memory.txt

9、工作日的工作时间内,每两小时执行一次echo “howdy”

# crontab -l
0 */2,9-18 * * 1-5 /bin/echo "hwdy"

脚本编程练习

10、创建目录/tmp/testdir-当前日期时间;

]# mkdir /tmp/testdir-$(date "+%F-%H-%M-%S")
]# ls -d /tmp/testdir*
/tmp/testdir-2016-10-16-07-03-50

11、在此目录创建100个空文件:file1-file100

]# touch file{1..100}
]# ll file* |wc -l
100

12、显示/etc/passwd文件中位于第偶数行的用户的用户名;

~]# sed -n 'n;p' /etc/passwd |awk -F: '{print $1}'

13、创建10用户user10-user19;密码同用户名;

#!/bin/bash
#
for i in {10..19};do
   if useradd user$i &>/dev/null ;then
       echo user$i |passwd --stdin user$i
   else
       echo "user$i is exists"
   fi
done

14、在/tmp/创建10个空文件file10-file19;

]# touch file{10..19}

15、把file10的属主和属组改为user10,依次类推。

]# for i in {10..19};do chown user$i:user$i file$i;done

原创文章,作者:N22-白蚁,如若转载,请注明出处:http://www.178linux.com/51911

(0)
N22-白蚁N22-白蚁
上一篇 2016-10-17
下一篇 2016-10-17

相关推荐

  • 上古神器之vim

    sed 前言:前面学到了文本处理三剑客之一grep,但是grep在有些时候显得力不从心,我们需要一款针对行操作的处理工具,没错,这就是sed流编辑器。 sed用法提炼: sed 's/(text1)(text2)(text3)/\1\2\3/'  vim 前言:强大的Linux如果没有一款疯狂的编辑器,常用的编辑操作会…

    Linux干货 2016-08-12
  • 文本处理课后小练习

    1、找出ifconfig命令结果中本机的所有IPv4地址 [root@wzc date]# ifconfig |grep -E -o  '(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]…

    Linux干货 2016-08-08
  • HipHop PHP实战(详解web运行模式)

    Note: These code examples assume the HipHop compiler is fully built. 1 . Setting Up Your Environment (构建环境) To get started, you need to configure two environment variables. cd…

    Linux干货 2015-04-10
  • 第六周 N21 总有刁民想害朕

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;    %s/\(^[[:space:]]\)/#\1/ 2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.…

    Linux干货 2016-08-08
  • 计算机组成及功能

    计算器:进行逻辑和算数运算 控制器:读取,接受,发出控制指令 存储器:存取程序和数据 I/O设备:输入指令并显示到标准输出设备

    Linux干货 2018-03-03
  • 计算机网络基础及常用工具

    Linux网络属性配置      计算机网络:      TCP/IP: 协议栈(使用)      ISO, OSI: 协议栈(学习)  MAC:Media Access Control      48bits:   &…

    Linux干货 2017-01-02

评论列表(1条)

  • 马哥教育
    马哥教育 2016-10-25 13:39

    作业写的很棒,请跟上学习进度,加油