homework week05

本周作业内容:

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

[[email protected] ~]# grep -wE ‘^(root|fedora|user1)‘ /etc/passwd |> awk -F‘[:]‘ ‘BEGIN{printf("username\tshell\n")}> {printf("%-15s\t%s\n",$1,$NF)}‘
username        shell
root            /bin/bash

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

[[email protected] ~]# egrep -o ‘[[:alpha:]]+\(\)‘ /etc/rc.d/init.d/functions 
str()
checkpid()
readlink()
fgrep()
loop()
loop()
run()
pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
success()
failure()
passed()
warning()
stage()
success()
failure()
passed()
warning()
action()
strstr()
confirm()
dev()
file()
true()
false()
sysctl()
random()
point()
crypto()

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

[[email protected] ~]# echo "/ab/12/cd/45ef" | grep -Eo ‘[^/.]*$‘
45ef

扩展:取出其路径名

[[email protected] ~]# echo "/ab/12/cd/45ef" | grep -Eo ‘^/.*/‘ | grep -o ‘^/.*[^/]‘
/ab/12/cd

使用命令

[[email protected] ~]# basename "/ab/12/cd/45ef"
45ef
[[email protected] ~]# dirname "/ab/12/cd/45ef"
/ab/12/cd

另外可以使用bash的字符串截取功能

[[email protected] ~]# s="/ab/12/cd/45ef"
[[email protected] ~]# echo ${s##*/}
45ef
[[email protected] ~]# echo ${s%/*}
/ab/12/cd

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

[[email protected] ~]# ifconfig | egrep -o ‘\b(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\b‘

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

[[email protected] ~]# cat /home/shell/iplist
1       192.168.1.100
2       192.168.100.20
3       11117.23.34.45
4       2559.23.34.123
5       255.255.255.0
6       255.255.248.0.12
7       255.255.240.0
8       1234.234.123.324
9       10.10.10.123.
10      224.234.23.123.34
11      0.0.0.0
12      10.10.10.10
13      12312.342432.12312.23

[[email protected] ~]# egrep -o ‘\<(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\>‘ /home/shell/iplist
192.168.1.100
192.168.100.20
255.255.255.0
255.255.248.0
255.255.240.0
10.10.10.123
224.234.23.123
0.0.0.0
10.10.10.10

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

[[email protected] ~]# cat /home/shell/malist 
[email protected]
[email protected]
[email protected]@com
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]@
[email protected]

[[email protected] ~]# egrep -o ‘[[:alnum:]_\.][email protected][[:alnum:]]+\.[[:alnum:]_\.]*[a-z]+‘ /home/shell/malist 
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

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

[[email protected] ~]# find /var/ \( -user root -a -group mail \) -ls
782573    4 drwxrwxr-x   2 root     mail         4096 Aug 29 16:08 /var/spool/mail
792338   12 -rw-------   1 root     mail         8666 Aug 23 17:04 /var/spool/mail/root

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

[[email protected] ~]# find / -type f \( -nouser -o -nogroup \) -ls

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

[[email protected] ~]# find / -type f -atime +3 -a \( -nouser -o -nogroup \) -ls

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

[[email protected] ~]# find /etc/ -perm -222 -ls

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

[[email protected] ~]# find /etc/ -type f -size +1M -ls

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

[[email protected] ~]# find /etc/init.d/ \( -perm -111 -a -perm -002 \) -ls

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

[[email protected] ~]# find /usr/ -type f -not  \( -user root -o -user bin -o -user hadoop \) -ls

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

[[email protected] ~]# find /etc -type f -not -perm -222 -ls

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

[[email protected] ~]# find /etc/ -type f -mtime -7 -not \( -user root -o -user hadoop \) -ls
时间: 2024-08-09 06:34:04

homework week05的相关文章

HDU 1789 Doing Homework again(贪心)

Doing Homework again Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadlin

uva 1489 - Math teacher&#39;s homework(数位dp)

题目链接:uva 1489 - Math teacher's homework 题目大意:给定n,k,以及序列m1,m2,-,mn, 要求找到一个长度为n的序列,满足0<=xi<=mi, 并且x1XORx2XOR-XORxn=k 解题思路:数位dp,在网上看了别人的代码,高大上... 假设有二进制数 k : 00001xxxx mi:0001xxxxx, 那么对于xi即可以满足任意的x1XORx2XOR-XORxi?1XORxi+1XOR-XORxn,根据这一点进行数位dp. dp[i][j]

HDU 1074 Doing Homework 状压DP

Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will r

HDU 1789 Doing Homework again

在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案直接交换就可以了. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; struct HomeWork { int de

[2016-03-28][HDU][1074][Doing Homework]

时间:2016-03-28 18:46:36 星期一 题目编号:[2016-03-28][HDU][1074][Doing Homework] 题目大意:给定n门科作业的期限时间和完成耗时,每科每超过一天就扣一份,求最少扣分数 分析:n只有15,二进制枚举,状态压缩,枚举每种科目完成的状态,更新下一个状态,求最小值 #include <cstring> #include <cstdio> using namespace std; const int maxstu = 1 <&

Homework (7th,Mar.)

第一题: 1 /* 2 定义一个水果类(fruit),水果类中有 3 属性:颜色(color).价格(price).重量(weigth), 4 再定义一个<测试类>, 5 创建一个苹果(apple)的对象, 颜色是"红色",价格是5.5,重量10g. 6 然后再创建一个香蕉(banana)的对象,颜色是"黄色",价格是4.2,重量5g. 7 最后输出:苹果的颜色.价格.重量. 8 香蕉的颜色.价格.重量. 9 */ 10 package Homework

hdu 5298 Solid Geometry Homework(几何)

题目链接:hdu 5298 Solid Geometry Homework 每个圈或者是平面将划分出两个区域,每次把一边区域取反即可.最后判断一下是否满足. #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int maxn = 3000; typedef long long ll; struct Poi

HDU 1074 Doing Homework(状压dp)

Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6299    Accepted Submission(s): 2708 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a l

HDU1789Doing Homework again(贪婪)

HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排在前面,扣分同样的依照最后期限前的排前面,然后用一个数组来表示第i天是否有安排.每次都将第i个作业放到它的最后期限的那天完毕,但假设这一天被占了,那么就仅仅能往前移动,找空暇的天.假设一直找到了0.那么说明这个作业是无法按时完毕了,就加上分数.假设某项作业完毕的最后期限比n还大,那么这个作业一定是能