马哥教育网络班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 08:36
下一篇 2016-10-17 08:36

相关推荐

  • linux常用命令实战练习–第一周作业

    1、使用date命令,显示前10天的年月日,显示后20天的年月日。 [root@chen ~]# date  Fri Jul 22 20:26:02 CST 2016 [root@chen ~]# date -d -10day &…

    Linux干货 2016-07-22
  • nginx相关配置及解释

    全局配置: user  nginx nginx; #运行程序的用户和用户组pid      /var/run/nginx.pid; #主控进程load_module /usr/lib64/nginx/modules/ngx_http_geoip_module.so;#加载模块 work进程的数量:通常为当前主…

    Linux干货 2017-05-07
  • ThirdWeek_SecondDay

    Python学习笔记整理

    Linux干货 2017-10-09
  • 运维工程师技能需求排行

    这是我今天在拉勾网搜索运维,翻完了4四页也招聘信息之后得到的,我的目的是想要看看之后的学习,哪个更应该成为重点,有些在我意料之中,有些还真的没想到,算是努力了一个小时的收获吧,分享给大家。
    注意:其中的看法仅代表个人观点,很多都是依靠我自己的学习经验和工作经验累积的

    Linux干货 2017-12-12
  • Python修饰器的函数式编程

    Python的修饰器的英文名叫Decorator,当你看到这个英文名的时候,你可能会把其跟Design Pattern里的Decorator搞混了,其实这是完全不同的两个东西。虽然好像,他们要干的事都很相似——都是想要对一个已有的模块做一些“修饰工作”,所谓修饰工作就是想给现有的模块加上一些小装饰(一些小功能,这些小功能可能好多模块都会用到),但又不让这个小…

    Linux干货 2016-08-15
  • 马哥教育网络班20期第3周课程练习

    答: 1、 [root@totooco ~]# who | cut -c1-9 | sort -u 2、 [totooco@totooco ~]$ who | cut -c1-9 | head -1 3、 [root@totooco ~]# cat /etc/passwd | cut -d: -f7 | grep -v /sbin/nologin | sor…

    Linux干货 2016-06-23

评论列表(1条)

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

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