未加星标

N25-第5周作业

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

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

[[email protected] ~]# grep -E '^[[:space:]]+.*' /boot/grub/gurb.conf

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

[[email protected] ~]# grep -E '^#[[:space:]]+[^[:space:]]+' /etc/rc.d/rc.sysinit

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

[[email protected] ~]# netstat -nat | grep -E '.*LISTEN[[:space:]]*'
tcp 0 0 192.168.122.1:53 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:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN

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

[[email protected] ~]# grep -E '^(.*)\>.*\1$' /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt

5、显示当前系统上的root,fedora或user1用户的默认shell;

[[email protected] ~]# grep -e ^root -e ^fedora -e ^user1 /etc/passwd | cut -d':' -f1,7
root:/bin/bash

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

[[email protected] ~]# grep -E '\<[[:alpha:]]*\>\(\)' /etc/rc.d/init.d/functions
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

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

[[email protected] yum.repos.d]# echo /etc/yum.repos.d/CentOS-Base.repo | grep -Eo '[^/]*/?$'
CentOS-Base.repo
[[email protected] yum.repos.d]# echo /etc/yum.repos.d/CentOS-Base.repo | grep -op '/.*/(?=.?\b)'
grep: invalid option -- 'p'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
[[email protected] yum.repos.d]# echo /etc/yum.repos.d/CentOS-Base.repo | grep -oP '/.*/(?=.?\b)'
/etc/yum.repos.d/

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

[[email protected] ~]# ifconfig | grep -E '\<([0-9]|([0-9][0-9])|(1[0-9][0-9])|(2[1-4][0-9])|(25[1-5]))\>'
inet 192.168.0.136 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::20c:29ff:fe23:d007 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:23:d0:07 txqueuelen 1000 (Ethernet)
RX packets 7650 bytes 701954 (685.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1547 bytes 184608 (180.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

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

[[email protected] ~]# grep -o '[[:alnum:]_.]*@[[:alnum:].]*'

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

[[email protected] ~]# ifconfig | grep -A 2 eth0 | grep -Eo '([0-9]{1,3}\.?){4}' | grep -v 255

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

[[email protected] ~]# find /var -user root -a -group mail
/var/spool/mail
/var/spool/mail/root

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

[[email protected] ~]# find / -nouser -o -nogroup -type f
find: ‘/proc/10683/task/10683/fd/6’: No such file or directory
find: ‘/proc/10683/task/10683/fdinfo/6’: No such file or directory
find: ‘/proc/10683/fd/6’: No such file or directory
find: ‘/proc/10683/fdinfo/6’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied

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

[[email protected] ~]# find / -type f -a -atime -3 -a \( -nouser -o -nogroup \)
find: ‘/proc/11258/task/11258/fdinfo/6’: No such file or directory
find: ‘/proc/11258/fdinfo/6’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied

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

[[email protected] ~]# find /etc -perm -222
/etc/mtab
/etc/fonts/conf.d/65-0-lohit-assamese.conf
/etc/fonts/conf.d/59-liberation-sans.conf
/etc/fonts/conf.d/65-lklug.conf
/etc/fonts/conf.d/10-scale-bitmap-fonts.conf
/etc/fonts/conf.d/69-gnu-free-mono.conf
/etc/fonts/conf.d/20-unhint-small-vera.conf
/etc/fonts/conf.d/65-0-lohit-nepali.conf
/etc/fonts/conf.d/65-0-lohit-kannada.conf
/etc/fonts/conf.d/25-unhint-nonlatin.conf
/etc/fonts/conf.d/65-0-nhn-nanum-gothic.conf
/etc/fonts/conf.d/30-metric-aliases.conf
/etc/fonts/conf.d/66-ucs-miscfixed.conf
/etc/fonts/conf.d/30-urw-aliases.conf
/etc/fonts/conf.d/65-0-jomolhari.conf
/etc/fonts/conf.d/40-nonlatin.conf
/etc/fonts/conf.d/65-sil-padauk.conf
/etc/fonts/conf.d/45-latin.conf
/etc/fonts/conf.d/69-gnu-free-serif.conf
/etc/fonts/conf.d/49-sansserif.conf
/etc/fonts/conf.d/50-user.conf
/etc/fonts/conf.d/51-local.conf

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

[[email protected] ~]# find /etc -size +1M -a -type f | xargs ls -lh
-rw-r--r--. 1 root root 1.4M Mar 5 2015 /etc/brltty/zh-tw.ctb
-rw-r--r--. 1 root root 1.4M Nov 21 2015 /etc/gconf/schemas/ekiga.schemas
-rw-r--r--. 1 root root 3.7M Nov 20 2015 /etc/selinux/targeted/policy/policy.29
-r--r--r--. 1 root root 6.7M Dec 26 01:21 /etc/udev/hwdb.bin

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

[[email protected] ~]# touch /etc/init.d/test.txt | chmod 113 /etc/init.d/test.txt
[[email protected] ~]# find /etc/init.d/ -perm -113 | xargs ls -lh
---x--x-wx. 1 root root 0 Jan 9 03:19 /etc/init.d/test.txt

16、查找/usr目录下不属于root、bin或hadoop的文件;

[[email protected] ~]# find /usr/ ! \( -user root -o -user bin -o -user hadoop \) -a -type f
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[[email protected] ~]# find /etc/ ! -perm -222 -a -type f

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

[[email protected] ~]# find /etc/ -mtime -7 -a ! \( -user root -o -user hadoop \) -a -type f

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: TI行权OPT
分页:12
转载请注明
本文标题:N25-第5周作业
本站链接:http://www.codesec.net/view/522212.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(12)