0810练习

思考题:删除yhy用户家目录,如何还原(root用户重新创建yhy的家目录,拷贝/etc/skel/.bash* 的三个文件到/etc/yhy/下即可)
[root@node1 Desktop]# id yhy
id: yhy: No such user
You have new mail in /var/spool/mail/root
[root@node1 Desktop]# useradd yhy
[root@node1 yhy]# cd /home/yhy/
[root@node1 yhy]# ll -d /home/yhy
drwx------ 4 yhy yhy 4096 Aug 10 18:59 /home/yhy
[root@node1 yhy]# ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .gnome2 .mozilla
[root@node1 yhy]# ls
[root@node1 yhy]# ls -a .bash*
.bash_history .bash_logout .bash_profile .bashrc
[root@node1 yhy]# rm -rf /home/yhy
[root@node1 yhy]# ls -a
[root@node1 yhy]# mkdir /home/yhy
You have new mail in /var/spool/mail/root
[root@node1 yhy]# ll -d /home/yhy/
drwxr-xr-x 2 root root 4096 Aug 10 19:05 /home/yhy/
[root@node1 yhy]# cp /etc/skel/.bash* /home/yhy
[root@node1 yhy]# ls -a /home/yhy
. .. .bash_logout .bash_profile .bashrc
[root@node1 yhy]# ll /home/yhy -a
total 20
drwxr-xr-x 2 yhy yhy 4096 Aug 10 19:08 .
drwxr-xr-x. 9 root root 4096 Aug 10 19:05 ..
-rw-r--r-- 1 root root 18 Aug 10 19:08 .bash_logout
-rw-r--r-- 1 root root 176 Aug 10 19:08 .bash_profile
-rw-r--r-- 1 root root 124 Aug 10 19:08 .bashrc
[root@node1 yhy]# chown yhy.yhy /home/yhy/
[root@node1 yhy]# ll /home/yhy -a
total 20
drwxr-xr-x 2 yhy yhy 4096 Aug 10 19:08 .
drwxr-xr-x. 9 root root 4096 Aug 10 19:05 ..
-rw-r--r-- 1 yhy yhy 18 Aug 10 19:08 .bash_logout
-rw-r--r-- 1 yhy yhy 176 Aug 10 19:08 .bash_profile
-rw-r--r-- 1 yhy yhy 124 Aug 10 19:08 .bashrc



1:显示/etc/passwd文件中不以/bin/bash结尾的行
[root@node1 ~]# grep -v "/bin/bash" /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown


2:找出/etc/passwd文件中的两位数或三位数的行
[root@node1 ~]# egrep "[0-9]{2,3}" /etc/passwd
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin


3:找出/etc/rc.d/rc.sysinit(centos 6)或/etc/grub2.cfg(centos 7)文件中,以至少一个空白字符开头,且后面有非空白字符的行
[root@node1 ~]# grep "^[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
. /etc/sysconfig/network
HOSTNAME=localhost
mount -n -t proc /proc /proc
mount -n -t sysfs /sys /sys >/dev/null 2>&1


4:找出”netstat -tan”命令的结果中以’LISTEN’后跟0、1或多个空白字符结尾的行
[root@node1 ~]# netstat -tan|grep "LISTEN[[:space:]]*$"
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LIST






• 找出/etc/passwd的所有的shell一共有多少种

[root@node1 ~]# sort -t: -k7 -u /etc/passwd|wc -l
5


• 复制/etc/grub2.conf文件至/tmp目录中,用查找替换命令删除/tmp/grub2.conf文件中以空白字符开头的行的行首的空白字符
:%s/^[[:space:]]\+/&/


• 复制/etc/rc.d/init.d/functions文件至/tmp目录中,用查找替换命令为/tmp/functions文件的每一个空白字符开头的行的首行加上#

:%s/^[[:space:]]\+.*/\#&/

• 为/tmp/grub2.cfg文件的前三行的行首加上#号

:1,3s/^./\#&/

• 将/etc/yum.repos.d/CentOS-Base.repo文件中所有的enabled=0替换为ennabled=1,所有的gpgcheck=0替换为gpgcheck=1

:%s/(enabled|gpgcheck)=0/\1=1/

转载于:https://www.cnblogs.com/hw19950508/p/7341210.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值