马哥教育网络20期+第6周练习博客

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

[root@localhost tmp]# cp /etc/rc.d/rc.sysinit  /tmp/ ; vim /tmp/rc.sysinit
%s/^[[:space:]]/# /g
或者
[root@localhost tmp]# sed 's/^[[:space:]]/# /g' /tmp/rc.sysinit

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

sed 's/^[[:space:]]\+//g' /tmp/grub.conf

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

 sed 's/^#[[:space:]]\+//' /tmp/rc.sysinit

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

[root@localhost tmp]# sed '1,3s/^/#/g' /tmp/grub.conf

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

[root@localhost tmp]# sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/CentOS-Media.repo

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

[root@localhost tmp]# vim /etc/crontab 
 
# *  *  *  *  * user-name command to be executed
  *  */4 * *  * root /bin/cp -rf /etc/* /backup/etc-`date +%Y%m%d%H%M`

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

  *  *  *  *  */2,4,6 root /bin/cp -rf /var/log/messages /backup/message_logs/messages-`date +%Y%m%d`

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

  *  */2  *  *  * root /bin/grep '^S' /proc/meminfo >> /stats/memory.txt

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

 *  8-17/2  *  *  */1-5 root /bin/ehco "howdy"; sleep 2h

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

[root@localhost tmp]# mkdir /tmp/testdir-`date +%Y%m%d%H%M%S`
[root@localhost tmp]# ls -a /tmp/testdir-20160716170653/
.  ..
[root@localhost tmp]#

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

[root@localhost 1]# cat 1.sh 
#!/bin/bash
for((i=1;i<=100;i++)); do
	touch /root/1/file$i;
done
[root@localhost 1]#

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

sed -n 'n;p' /etc/passwd

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

[root@localhost 1]# cat 1.sh 
#!/bin/bash
for ((i=10;i<=19;i++));do
	if (id user$i > /dev/null);then
		echo "user$i" | passwd --stdin user$i > /dev/null
	else 
		useradd user$i
		echo "user$i" | passwd --stdin user$i > /dev/null
	fi
done
[root@localhost 1]#

14、在/tmp/创建10个空文件file10-file19;      15、把file10的属主和属组改为user10,依次类推。

[root@localhost 1]# cat 2.sh 
#!/bin/bash
for ((i=10;i<=19;i++));do
	if [ -f /tmp/file$i ];then
		chown user$i:user$i /tmp/file$i
	else 
		touch /tmp/file$i
		chown user$i:user$i /tmp/file$i
	fi
done
[root@localhost 1]#



原创文章,作者:Net20-deamon,如若转载,请注明出处:http://www.178linux.com/24360

(0)
Net20-deamonNet20-deamon
上一篇 2016-07-16 14:41
下一篇 2016-07-16 21:58

相关推荐

  • Linux简述

    计算机诞生                                                  …

    2017-03-18
  • 【招聘福利】上海雪山金融/高级运维工程师/待遇面谈/家嘴站/

    你好:     www.xueshandai.com为本公司的相关网址 可供了解 公司介绍     上海雪山金融信息服务有限公司成立于2012年1月,位于上海市浦东新区陆家嘴,是一家专业的金融服务公司,是在中国大力支持中小微企业发展,建设多层次资本市场,资产证券化和利率市场化的公平和透明的宏观背景下…

    Linux职位 2015-06-05
  • 内置数据结构

    list,tuple,str,bytes,bytearray,set,切片,分装解构,冒泡法

    2018-03-31
  • 虚拟主机的实现

    示例1:基于ip 编辑配置文件,切换到最后一行,增加: <VirtualHost 192.168.1.117:80>     ServerName web1.ams.com     DocumentRoot "/vhosts/web1/htdocs" </VirtualHost&g…

    Linux干货 2016-08-05
  • 系统启动及恢复

    一、知识整理 1、modinfo命令:显示模块的详细描述信息: -n 只显示模块文件路径 -p 显示模块参数 -a auther -d description -l license协议 modprobe命令:装载或卸载内核 -r卸载内核,同rmmod 配置文件:/etc/modprobe.d/*.conf depmod命令:内核模块依赖关系文件及系统信息映射…

    Linux干货 2016-09-22
  • Redhat的Linux产品版本AS/ES/WS的联系与区别

    Redhat 有两大Linux产品系列,其一是免费的Fedora Core系列主要用于桌面版本,提供了较多新特性的支持。另外一个产品系列是收费的Enterprise系列,这个系列分成:AS/ES/WS等分支,他 们都是redhat企业级Linux,简称为 RHEL AS 是超级服务器版(Advanced Server),他在标准Linux内核的基础上,做了性…

    Linux干货 2015-03-20

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-17 20:49

    写的很好,排版也很漂亮,第二题的复制那?周的时候不需要除以可以直接使用,加油