第五周作業

1、顯示當前系統上root、fedora或user1用戶的默認shell;

[root@localhost ~]# awk -F: '/^(root|user1|fedora)/{print $1,"shell is",$NF}' /etc/passwd
root shell is /bin/bash
fedora shell is /bin/bash
user1 shell is /bin/bash

2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();

[root@localhost ~]# egrep -o '^(_|[a-z]+).*\(\)' /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()

3、使用echo命令輸出一個絕對路徑,使用grep取出其基名;

[root@localhost ~]# echo /etc/fstab | grep  -E  -o  "[^/]+/?$"
fstab

    擴展:取出其路徑名

[root@localhost ~]# echo /etc/fstab | grep  -E  -o  "^/[^/].+/" 
/etc/

4、找出ifconfig命令結果中的1-255之間數字;

[root@thinkmail ~]# ifconfig | grep  -E  -o  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
29
192
168
54
76
192
168
54
255
255
255
255
1
1
4
25
5
127
1
255
1

5、挑戰題:寫一個模式,能匹配合理的IP地址;

[root@thinkmail ~]# ifconfig eth0 |grep 'inet addr:'|egrep -o '[1][0-9]{1,2}.[0-9]{1,3}.[0-9]{1,3}.[1-9][1-5]{1,2}'
192.168.54
192.168.54.255

6、挑戰題:寫一個模式,能匹配出所有的郵件地址;

[root@thinkmail ~]# egrep --color  '[0-9A-Za-z]+@[0-9A-Za-z]+.[a-z]{1,3}' aa
hexinhai@aaa.com
adjaldal@ok.com
jdlalaf@baidu.cn
jdlalaf@baidu.cc
jdlalaf@baidu.net

7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;

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

8、查找當前系統上沒有屬主或屬組的文件;

[root@localhost tmp]# find /tmp -nouser -o -nogroup |xargs ls -l
-rw-r--r-- 1  503 503 0 9月  13 16:50 /tmp/aa
-rw-r--r-- 1 root 503 0 9月  13 16:51 /tmp/bb

     進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;

find /tmp -nouser -o -nogroup -atime -3 |xargs ls -l

9、查找/etc目錄下所有用戶都有寫權限的文件;

[root@thinkmail tmp]# find /etc/ -type f -perm -222 -ls
131264    0 -rw-rw-rw-   1 root     root            0 9月 13 16:55 /etc

10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;

[root@thinkmail tmp]# find /etc/ -size +1M |xargs ls -lh
-rw-r--r--. 1 root root 6.9M 9月   9 13:54 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 6.9M 9月   9 13:54 /etc/selinux/targeted/policy/policy.24

11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;

[root@thinkmail tmp]# find /etc/init.d/ -perm -111 |xargs  ls -l
-rwxr-xr-x  1 root root     0 9月  13 17:01 /etc/init.d/aaa.sh
-rwxr-xr-x  1 root root  1288 5月  12 04:43 /etc/init.d/abrt-ccpp
-rwxr-xr-x  1 root root  1628 5月  12 04:43 /etc/init.d/abrtd
-rwxr-xr-x  1 root root  1642 5月  12 04:43 /etc/init.d/abrt-oops
-rwxr-xr-x  1 root root  1818 2月  17 2016 /etc/init.d/acpid
-rwxr-xr-x  1 root root  2062 2月  20 2015 /etc/init.d/atd
-rwxr-xr-x  1 root root  3580 5月  11 14:17 /etc/init.d/auditd
-rwxr-xr-x. 1 root root  4043 2月  22 2013 /etc/init.d/autofs
-r-xr-xr-x  1 root root  1343 8月  24 02:37 /etc/init.d/blk-availability
-rwxr-xr-x  1 root root  5221 7月  13 00:27 /etc/init.d/cgconfig
-rwxr-xr-x  1 root root  3580 7月  13 00:27 /etc/init.d/cgred
-rwxr-xr-x  1 root root 11864 7月  24 2015 /etc/init.d/cpuspeed
-rwxr-xr-x. 1 root root  2793 7月  19 2011 /etc/init.d/crond
-rwxr-xr-x  1 root root  1801 10月 15 2014 /etc/init.d/haldaemon
-rwxr-xr-x. 1 root root  5829 1月   9 2013 /etc/init.d/halt
-rwxr-xr-x. 1 root root  9515 2月  22 2013 /etc/init.d/ip6tables

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

[root@thinkmail init.d]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)
/usr/xiaoxin
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;

[root@thinkmail init.d]# find /etc/ -perm -444

14、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;

find /etc -mtime -7 -a -not \( -user root -o -user hadoop \) -ls

原創文章,作者:xiaoxin,如若轉載,請注明出處:http://www.www58058.com/46116

(0)
xiaoxinxiaoxin
上一篇 2016-09-15
下一篇 2016-09-15

相關推薦

  • 淺談DNS基本原理以及實現方法(一)

     DNS(Domain Name System,域名系統),是目前互聯網上最不可或缺的服務器之一,我們在互聯網從訪問一個網站,到發送一封電子郵件,再到定位域中的域控制器,無時無刻不再使用著DNS為我們提供的服務,那為什么我們會需要這樣一個服務那?帶著這樣一個疑問讓我們先來認識一下什么是DNS吧  DNS最核心的工作就是域名解析,也就是把計…

    Linux干貨 2015-12-15
  • man 命令簡單介紹

    man n command man手冊頁分為下面幾個部分: 1 普通命令2 內核提供的系統調用3 庫調用4 設備文件5 文件格式規范6 游戲7 雜項8 系統管理命令

    Linux干貨 2018-03-03
  • 初識Linux

    1 硬件:cpu,內存,輸入輸出設備 功能:計算,存放cpu暫時計算的數據,接受輸入和輸出反應 2 Debian Ubuntu => mint knopix Slackware: S.u.S.E => OpenSUSE SLES RedHat: RedHat Enterprise Linux => CentOS FedoraCore 3 1…

    Linux干貨 2017-07-11
  • 計算機之路及初識linux

    寫在前面:     很抱歉,上周的事兒,拖到這周,也是個半成品,加班就不多說了,每個人都很忙,總要自己找時間。本計劃這個周末好好補補,無奈身不由己,剛剛回來。    還好昨夜先起了個初稿,總算是有些東西可以交代給自己,想到馬哥說的,完成遠比完善重要,雖然來不及完善,先發出來吧,有了框架,至少知道自己做過什么。盡快排版吧…

    Linux干貨 2016-12-05
  • linux樹狀結構

    linux 目錄結構   /:根目錄,一般根目錄下只存放目錄,不要存放文件,/etc、/bin、/dev、/lib、/sbin應該和根目錄放置在一個分區中 /bin:/usr/bin:可執行二進制文件的目錄,如常用的命令ls、tar、mv、cat等。 /boot:放置linux系統啟動時用到的一些文件。/boot/vmlinuz為linux的內核文…

    Linux干貨 2016-08-05
  • 軟件編譯安裝小結

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1439073     本文主要針對 configure 和 cmake 做一個介紹以及我們重新配置編譯參數文件時,都需要做哪些清…

    Linux干貨 2016-08-15

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-19 18:29

    匹配ip地址不對,在好好想想

欧美性久久久久