N26-第五周博客作業

一、顯示當前系統上root、fedorauser1用戶的默認shell

[root@promote home]# grep -E ‘^(root|fedora|user1)’ /etc/passwd |
cut -d : -f7

/bin/bash

/bin/bash

/bin/bash

[root@promote home]#

注:僅egrep支持(a|b)這種模式

 

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

[root@VM_221_40_centos ~]# grep -o
“\<[_[:alpha:]]\+\>(.*)” /etc/rc.d/init.d/functions

checkpid()

__pids_var_run()

__pids_pidof()

daemon()

killproc()

if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1)
exit 1;delay+=d*$1} END {printf(“%d”,delay+0.5)}’)

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()

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos
init.d]# echo $PWD | grep -o “[^/]\+$”

init.d

[root@VM_221_40_centos
init.d]#

 

 

 擴展:取出其路徑名

[root@VM_221_40_centos init.d]# echo $PWD | grep -o
“^/.*/”

/etc/rc.d/

[root@VM_221_40_centos init.d]#

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

[root@VM_221_40_centos init.d]# ifconfig | grep -E -o
“\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>”

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

grep -E
“\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])”
/tmp/ip

 

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

郵箱地址中用戶名可以是數字、字母(分大小寫)、下劃線。

grep -Eo “\<[a-z,A-Z,0-9,_-]+@[A-Z,a-z,0-9,-]+\.[A-Z,a-z,0-9]{2,}\>”
/tmp/mail

或者

grep -o
“\<[a-z,A-Z,0-9,_]\+@[A-Z,a-z,0-9,-]\+\.[A-Z,a-z,0-9]\{2,\}\>”
/tmp/mail

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

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

 24631    4 drwxrwxr-x   2 root     mail         4096 May 15 00:22
/var/spool/mail

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos ~]# find /home -nouser -a -nogroup -ls | more

278530    4 drwx——   3 1000     1000         4096 May 15 00:23
/home/gentoo

278534    4 -rw——-   1 1000     1000          126 May 15 02:02
/home/gentoo/.bash_hi

story

278535    4 drwxrwxr-x   2 1000     1000         4096 May 15 00:23
/home/gentoo/gen

278531    4 -rw-r–r–   1 1000     1000          231 Aug  3  2016
/home/gentoo/.bashrc

278532    4 -rw-r–r–   1 1000     1000           18 Aug  3  2016
/home/gentoo/.bash_lo

gout

278533    4 -rw-r–r–   1 1000     1000          193 Aug  3  2016
/home/gentoo/.bash_pr

ofile

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos ~]# find /home
-nouser -a -nogroup -a -ctime -3 -ls | more

278530    4 drwx——   3 1000     1000         4096 May 15 00:23 /home/gentoo

278534    4 -rw——-   1 1000     1000          126 May 15 02:02
/home/gentoo/.bash_hi

story

278535    4 drwxrwxr-x   2 1000     1000         4096 May 15 00:23 /home/gentoo/gen

278531    4 -rw-r–r–   1 1000     1000          231 Aug  3  2016
/home/gentoo/.bashrc

278532    4 -rw-r–r–   1 1000     1000           18 Aug  3  2016
/home/gentoo/.bash_lo

gout

278533    4 -rw-r–r–   1 1000     1000          193 Aug  3  2016
/home/gentoo/.bash_pr

ofile

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos ~]# find ./ -perm -222 –ls

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

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

 

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

(0)
lixinkuanlixinkuan
上一篇 2017-05-15 16:38
下一篇 2017-05-15 19:27

相關推薦

  • 條件判斷if、case與文件查找locate、find及相關練習

    一、條件選擇 1、if:按條件執行腳本中的內容,可以使用嵌套結構,有單分支、雙分支和多分支結構,每個條件中可以有不止一條語句,如果有多條語句,可以用and(-a)或or(-o)連接在一起,但不能使用&&或||: if COMMANDS; then     COMMANDS;   &n…

    Linux干貨 2016-08-18
  • 天神之劍Vim編輯器

    一.概述和基本用法及一些描述 vi:Visual Interface 文本編輯器 文本ASCII , Unicode 文本編輯種類: 行編輯器:sed 全屏編輯器:nano,vi vim – Vi Improved 其他編輯器: gedit 一個簡單的圖形編輯器 gvim 一個vim編輯器的圖形版本 基本用法  vim [OPTION]…

    Linux干貨 2016-08-15
  • jenkins+gitlab構建安卓自動編譯環境

        因工作關系接觸到接觸到安卓自動編譯環境,網上的資料都推薦了jenkins,因為第一次接觸安卓和jenkins,踩了不少的坑,有總結才有進步。    gitlab環境之前已經安裝完成可用,具體步驟另外詳解吧。本例目標是在gitlab可用前提下,通過jenkins將git倉庫的代碼自行編譯打包,生成可用的apk安裝…

    Linux干貨 2016-07-16
  • iptables

    一、前言 什么是iptables?當我們啟動iptables時,使用service命令可以啟動iptables。但是并非使用service啟動的iptables就能說明其是一個服務。Iptables是一個便以我們寫規則的工具,真正起作用的是內核中的netfilter一個框架。Netfilter內置了5個hook函數,當一個數據包交由此機器時,經過這5個hoo…

    Linux干貨 2015-10-27
  • Linux基礎小模塊

    1.基礎知識小塊:shell 由shell程序的自帶命令:即為內置命令(builtin) 獨立的可執行程序文件、文件名 :即為外部命令  [root@localhost~]#ls      ~用戶當前所在目錄  #:命令提示符(管理員帳號root)  $:普通用戶   &nbsp…

    Linux干貨 2016-08-05
  • N22-妙手-第三周博客作業

    1、列出當前系統上所有已經登錄的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。 [root@localhost ~]# who | cut -d' ' -f1 | uniq -c     &nb…

    Linux干貨 2016-09-19

評論列表(1條)

  • luoweiro
    luoweiro 2017-06-26 23:05

    進度要跟上了,加油。

欧美性久久久久