第五周作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第五周作业相关的知识,希望对你有一定的参考价值。
1、显示当前系统上root、fedora或user1用户的默认shell;
grep -E ‘^root|fedora|allan:‘ /etc/passwd |cut -d: -f1,7 #显示root,allan默认shell
root:/bin/bash
allan:/bin/bash
2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
egrep ‘[_[:alpha:]]+\(\)‘ /etc/rc.d/init.d/functions
checkpid() {
__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() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
3、使用echo命令输出一个绝对路径,使用grep取出其基名;
echo ‘/etc/networks‘ | egrep -o ‘[[:alpha:]]+/?$‘ | cut -d/ -f1
networks
扩展:取出其路径名
echo ‘/etc/networks‘ | egrep -o ‘.*/‘
/etc/
4、找出ifconfig命令结果中的1-255之间数字;
ifconfig | egrep ‘\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>
inet 192.168.113.128 netmask 255.255.255.0 broadcast192.168.113.255
inet6 fe80::20c:29ff:fe58:9f08 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:58:9f:08 txqueuelen 1000 (Ethernet)
RX packets 1232 bytes 110338 (107.7 KiB)
TX packets 877 bytes 95121 (92.8 KiB)
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>
5、挑战题:写一个模式,能匹配合理的IP地址;
((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)
6、挑战题:写一个模式,能匹配出所有的邮件地址;
var reEmail=/^(?:\w+\.?)*\[email protected](?:\w+\.?)*\w+$/;
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
find /var/ -user root -a -group mail -ls
16819288 4 drwxrwxr-x 2 root mail 4096 Aug 29 11:30 /var/spool/mail
8、查找当前系统上没有属主或属组的文件;
find / -nouser -a -nogroup -ls
find: ‘/proc/3426/task/3426/fd/6’: No such file or directory
find: ‘/proc/3426/task/3426/fdinfo/6’: No such file or directory
find: ‘/proc/3426/fd/6’: No such file or directory
find: ‘/proc/3426/fdinfo/6’: No such file or directory
进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
find / -nouser -a -nogroup -a -atime -3 -exec stat {} \;
find: ‘/proc/3433/task/3433/fd/6’: No such file or directory
find: ‘/proc/3433/task/3433/fdinfo/6’: No such file or directory
find: ‘/proc/3433/fd/6’: No such file or directory
find: ‘/proc/3433/fdinfo/6’: No such file or directory
9、查找/etc目录下所有用户都有写权限的文件;
find /etc -perm -222 -ls>/tmp/findperm
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
find /etc/ -size +1M -a -type f -exec ls -lh {} \;
-r--r--r--. 1 root root 6.7M Aug 12 14:11 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 3.7M Nov 21 2015 /etc/selinux/targeted/policy/policy.29
11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
find /etc/init.d/ -perm -113 -ls
12、查找/usr目录下不属于root、bin或hadoop的文件;
find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls
462063 0 drwx------ 2 polkitd root 6 Jun 10 2014 /usr/share/polkit-1/rules.d
26046807 16 -rwsr-sr-x 1 abrt abrt 15336 Dec 1 2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cach
13、查找/etc/目录下至少有一类用户没有写权限的文件;
find ./ -not -perm -222 -ls
25165953 4 dr-xr-x--- 2 root root 4096 Aug 30 12:03 ./
26768063 4 -rw-r--r-- 1 root root 18 Dec 29 2013 ./.bash_logout
26870528 4 -rw-r--r-- 1 root root 176 Dec 29 2013 ./.bash_profile
26870529 4 -rw-r--r-- 1 root root 176 Dec 29 2013 ./.bashrc
26870530 4 -rw-r--r-- 1 root root 100 Dec 29 2013 ./.cshrc
26870531 4 -rw-r--r-- 1 root root 129 Dec 29 2013 ./.tcshrc
26873169 4 -rw------- 1 root root 1548 Aug 12 13:50 ./anaconda-ks.cfg
26873181 12 -rw------- 1 root root 11886 Aug 29 16:52 ./.bash_history
26880279 0 -rw-r--r-- 1 root root 0 Aug 30 12:03 ./findnouser
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
find ./ -mtime -7 -a -not \( -user root -o -user hadoop \) -ls
以上是关于第五周作业的主要内容,如果未能解决你的问题,请参考以下文章