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

1、  显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

[root@localhost ~]# grep "^[[:space:]]\+.*" /boot/grub/grub.conf

         root (hd0,0)

         kernel /vmlinuz-2.6.32-504.el6.i686 ro root=UUID=e6891007-5edb-4ec9-b9af-2e0a319bcde5 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

         initrd /initramfs-2.6.32-504.el6.i686.img

[root@localhost ~]#

 

2、  显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/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,

# filesystems are NOT unmounted in single user mode.

# The 'no' applies to all listed filesystem types. See mount(8).

# Update quotas if necessary

# Check to see if a full relabel is needed

# Initialize pseudo-random number generator

# Configure machine if necessary.

# Clean out /.

# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might…

# Clean up /var.

# Clean up utmp/wtmp

# Clean up various /tmp bits

# Make ICE directory

# Start up swapping.

# Set up binfmt_misc

# Boot time profiles. Yes, this should be somewhere else.

# Now that we have all of our basic modules loaded and the kernel going,

# let's dump the syslog ring somewhere so we can find it later

# create the crash indicator flag to warn on crashes, offer fsck with timeout

# Let rhgb know that we're leaving rc.sysinit

[root@localhost ~]#

 

3、  打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"

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:*                   LISTEN     

tcp        0      0 :::22                       :::*                        LISTEN     

tcp        0      0 ::1:631                     :::*                        LISTEN     

tcp        0      0 ::1:25                      :::*                        LISTEN     

[root@localhost ~]#

 

4、  添加用户bash, testbash, basher, nologin (此一个用户的shell/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

[root@localhost ~]# egrep "^([[:alnum:]]).*\1$" /etc/passwd

nobody:x:99:99:Nobody:/:/sbin/nologin

ntp:x:38:38::/etc/ntp:/sbin/nologin

nologin:x:2007:2007::/home/nologin:/sbin/nologin

[root@localhost ~]#

 

5、  显示当前系统上rootfedorauser1用户的默认shell

[root@localhost ~]# grep  -E '^(root|fedora|user1)'  /etc/passwd

root:x:0:0:root:/root:/bin/bash

[root@localhost ~]#

 

6、  找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello()

[root@localhost ~]# grep  "[[:alpha:]]\+()" /etc/rc.d/init.d/functions

fstab_decode_str() {

checkpid() {

__readlink() {

__fgrep() {

__umount_loop() {

__umount_loopback_loop() {

__pids_var_run() {

__pids_pidof() {

daemon() {

killproc() {

pidfileofproc() {

pidofproc() {

status() {

echo_success() {

echo_failure() {

echo_passed() {

echo_warning() {

update_boot_stage() {

success() {

failure() {

passed() {

warning() {

action() {

strstr() {

confirm() {

get_numeric_dev() {

is_ignored_file() {

is_true() {

is_false() {

apply_sysctl() {

key_is_random() {

find_crypto_mount_point() {

init_crypto() {

[root@localhost ~]#

 

7、  使用echo命令输出一个绝对路径,使用grep取出其基名;

[root@localhost ~]# echo /etc/sysconfig/network-scripts | grep -o "[^/]*$"

network-scripts

[root@localhost ~]#

 

扩展:取出其路径名

[root@localhost ~]# echo /etc/sysconfig/network-scripts | grep -oP "^.*(?=/)"

/etc/sysconfig

[root@localhost ~]#

 

8、  找出ifconfig命令结果中的1-255之间数字

[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,2}|2[0-5]{1,2}"

29

63

3

89

19

2

16

8

1

13

5

19

2

16

8

1

255

255

255

255

6

8

20

29

63

38

9

64

15

1

68

9

8

36

12

4

1

76

81

97

75

73

2

213

59

88

2

19

202

4

12

7

1

255

6

1

12

8

65

53

6

1

26

26

14

34

1

4

14

34

1

4

[root@localhost ~]#

 

9、  挑战题:写一个模式,能匹配合理的IP地址;

[root@localhost etc]# ifconfig | egrep -o "[1-9]{1,3}\.[1-9]{1,3}\.[0-9]{1,3}\.[1-9]{1,3}"

192.168.10.135

192.168.10.255

[root@localhost etc]#

 

10、              挑战题:写一个模式,能匹配出所有的邮件地址;

[root@localhost etc]# cat  mail.txt

ddw@163.com

ddw@qq.com

ddw1@129.com

ddw

ddw3444

 

[root@localhost etc]# cat mail.txt | grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$'

ddw@163.com

ddw@qq.com

ddw1@129.com

[root@localhost etc]#

 

 

11、              查找/var目录下属主为root,且属组为mail的所有文件或目录;

[root@localhost ~]# find /var/ -user root -group mail

/var/spool/mail

/var/spool/mail/root

[root@localhost ~]#

 

12、              查找当前系统上没有属主或属组的文件;

[root@localhost ~]# find / -nouser -o -nogroup

find: `/proc/1470/task/1470/fd/5': No such file or directory

find: `/proc/1470/task/1470/fd/5': No such file or directory

find: `/proc/1470/task/1470/fdinfo/5': No such file or directory

find: `/proc/1470/task/1470/fdinfo/5': No such file or directory

find: `/proc/1470/fd/5': No such file or directory

find: `/proc/1470/fd/5': No such file or directory

find: `/proc/1470/fdinfo/5': No such file or directory

find: `/proc/1470/fdinfo/5': No such file or directory

/home/mageia

/home/mageia/.bashrc

/home/mageia/.bash_logout

/home/mageia/.bash_profile

/home/mageia/.mozilla

/home/mageia/.mozilla/extensions

/home/mageia/.mozilla/plugins

/home/mageia/.gnome2

/home/mandriva

/home/mandriva/.bashrc

/home/mandriva/.bash_logout

/home/mandriva/.bash_profile

/home/mandriva/.mozilla

/home/mandriva/.mozilla/extensions

/home/mandriva/.mozilla/plugins

/home/mandriva/.gnome2

/var/spool/mail/mageia

[root@localhost ~]#

 

 进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

[root@localhost ~]# find / -nouser -o -nogroup -a  -atime -3

find: `/proc/1474/task/1474/fd/5': No such file or directory

find: `/proc/1474/task/1474/fd/5': No such file or directory

find: `/proc/1474/task/1474/fdinfo/5': No such file or directory

find: `/proc/1474/task/1474/fdinfo/5': No such file or directory

find: `/proc/1474/fd/5': No such file or directory

find: `/proc/1474/fd/5': No such file or directory

find: `/proc/1474/fdinfo/5': No such file or directory

find: `/proc/1474/fdinfo/5': No such file or directory

/home/mageia

/home/mageia/.bashrc

/home/mageia/.bash_logout

/home/mageia/.bash_profile

/home/mageia/.mozilla

/home/mageia/.mozilla/extensions

/home/mageia/.mozilla/plugins

/home/mageia/.gnome2

/home/mandriva

/home/mandriva/.mozilla

/home/mandriva/.mozilla/extensions

/home/mandriva/.mozilla/plugins

/home/mandriva/.gnome2

/var/spool/mail/mageia

[root@localhost ~]#

 

13、              查找/etc目录下所有用户都有写权限的文件;

[root@localhost ~]# find /etc -perm -222

 

14、              查找/etc目录下大于1M,且类型为普通文件的所有文件;

[root@localhost ~]# find /etc -type f -size +1M

/etc/gconf/gconf.xml.defaults/%gconf-tree.xml

/etc/selinux/targeted/modules/active/policy.kern

/etc/selinux/targeted/policy/policy.24

[root@localhost ~]#

 

15、              查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

[root@localhost ~]# find /etc/init.d -perm -113

/etc/init.d

[root@localhost ~]#

 

16、              查找/usr目录下不属于rootbinhadoop的文件;

[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls

812604    8 -rwsr-xr-x   1 abrt     abrt         5524 Oct 16  2014 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

[root@localhost ~]#

 

17、              查找/etc/目录下至少有一类用户没有写权限的文件;

[root@localhost ~]# find /etc ! -perm +222 -ls

270181    4 -r–r–r–   1 root     root           76 Aug 31  2014 /etc/lvm/profile/thin-generic.profile

270180    4 -r–r–r–   1 root     root          827 Oct 15  2014 /etc/lvm/profile/metadata_profile_template.profile

270182    4 -r–r–r–   1 root     root           80 Aug 31  2014 /etc/lvm/profile/thin-performance.profile

270179    4 -r–r–r–   1 root     root         2231 Oct 15  2014 /etc/lvm/profile/command_profile_template.profile

263545    4 ———-   1 root     root          881 Jul 28 19:43 /etc/gshadow

262577    4 -r——–   1 root     root           45 May  2 07:57 /etc/openldap/certs/password

270407    4 -r–r—–   1 root     root         4002 Mar  1  2012 /etc/sudoers

263665    4 ———-   1 root     root         1306 Jul 28 19:43 /etc/shadow

262349  316 -r–r–r–   1 root     root       321332 May  2 07:56 /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt

262350  236 -r–r–r–   1 root     root       240762 May  2 07:56 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

262351  188 -r–r–r–   1 root     root       191741 May  2 07:56 /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem

262352  188 -r–r–r–   1 root     root       191772 May  2 07:56 /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem

262353  176 -r–r–r–   1 root     root       179212 May  2 07:56 /etc/pki/ca-trust/extracted/java/cacerts

262869    4 -r–r–r–   1 root     root          460 Oct 15  2014 /etc/dbus-1/system.d/cups.conf

262187    4 ———-   1 root     root         1276 Jul 28 19:43 /etc/shadow-

262871    4 -r–r–r–   1 root     root          146 Oct 15  2014 /etc/pam.d/cups

270184    4 -r-xr-xr-x   1 root     root         2134 Oct 15  2014 /etc/rc.d/init.d/lvm2-lvmetad

270185    4 -r-xr-xr-x   1 root     root         2757 Oct 15  2014 /etc/rc.d/init.d/lvm2-monitor

270183    4 -r-xr-xr-x   1 root     root         1340 Oct 15  2014 /etc/rc.d/init.d/blk-availability

262722    4 -r–r–r–   1 root     root          324 Oct 14  2014 /etc/ld.so.conf.d/kernel-2.6.32-504.el6.i686.conf

[root@localhost ~]#

 

18、              查找/etc目录下最近一周内其内容被修改过,且不属于roothadoop的文件;

[root@localhost ~]# find /etc/ -not \( -user root -o -user hadoop \) -a  -ctime -7 -ls

 

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

(0)
dengdw0917dengdw0917
上一篇 2016-08-02
下一篇 2016-08-02

相关推荐

  • Lamp应用

    练习:分别使用CentOS 7和CentOS 6实现以下任务 (1) 配置三个基于名称的虚拟主机; (a) discuzX (b) wordpress (c) https: phpMyAdmin (2) 对discuzX的主页做压测; 分别给出并发10, 100, 200, 500等每秒的响应数 建立私有CA (umask 077;openssl genrs…

    Linux干货 2016-10-12
  • for,while,until简介

    Shell(以Bash为例)中的循环语句一般有for、while、until这几种,偶尔还有写错语法的时候,这里结合实例来自己总结一下。也为今后使用提供一个快捷的资料获取渠道。 一、for循环语句 实例1.1 最基本的for循环: (传统的形式,for var in …) 代码如下: #!/bin/bashfor x in one two three fou…

    Linux干货 2016-08-22
  • 新手报到

    在开班的第一天为自己立下flag,看毕业时能否实现自己的预期。

    2018-03-26
  • 马哥教育网络版25期+第一周作业

    1、描述计算机的组成及其功能 计算机是由CPU,控制器,RAM,输入设备,输出设备组成的 2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别 现如今主流的LINUX发行版系列主要有: Debian,Slackware,Redhat,这些发行版都是基于GUNLinux开发的,不过是由不同的组织或团体开发并发行的。 3、描述Linux的哲学思想,…

    Linux干货 2016-12-05
  • Linux网站架构系列之Apache—-进阶篇

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1320167 本篇博文为Linux网站架构系列之apache的第二篇,我将带大家一起学习apache的编译参数,目录结构和配置文件等方面的知识,实现对apac…

    Linux干货 2016-08-15
  • Linux用户和组的相关管理命令(一、用户的相关命令)

    Linux是一个可以实现多用户登录的操作系统,通过su – 用户名 可以进行用户之间的切换,从而完成不同登录用户下对私有文件的操作,同时,每个用户有且只有一个主组,但是可以有零个或多个附加组,每个组可以是一个用户的主组,同时还可以是多个用户的附加组。因此,熟练掌握用户和组的相关命令十分重要。 首先,要了解用户和组的配置文件各有两个: 与用户相关的…

    2017-07-22

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-02 11:23

    写的很好,排版还可以在漂亮一点,加油,8题不对,100-199的匹配不出来吧