grep 正則表達式 find

1.顯示當前系統上root,fedora 或user1用戶的默認shell
[root@centos7 ~]# grep -E? “^(root|fedora|user1)” /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:2003:2003::/home/fedora:/bin/bash
user1:x:2004:2004::/home/user1:/bin/bash
2.找出 /etc/rc.d/init.d/functions文件中某個單詞后面跟一組小括號的行,形如:hello();
[root@centos7 ~]# cat /etc/rc.d/init.d/functions |grep -E “[[:alpha:]]{1,}\(\) “
checkpid() {
__kill_pids_term_kill_checkpids() {
__kill_pids_term_kill() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
3.使用echo命令輸出一個絕對路徑,使用grep取出莫個基名。
[root@centos7 fedora]# echo /home/fedora/|grep -E “[[:alpha:]]{1,}/$”
/home/fedora/
4.找出ifconfig命令結果中的1-255之間的數字。
[root@centos7 ~]# ifconfig|grep -E -o? “\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>”
5挑戰題:寫一個模式,能匹配合理的ip地址;
[root@centos7 ~]# ifconfig|grep -E -o? “\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>”
192.168.119.137
255.255.255.0
192.168.119.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255
6.挑戰題:寫一個模式,能匹配出所有的郵件地址;
[root@centos7 ~]# cat email |grep -E “^([0-9]|[a-zA-Z])([[:alnum:]]|[[:punct:]])+@[[:alnum:]]*\.(com|cn)$”
7.查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
[root@centos7 var]# find /var/ -user root -a -group mail -ls
33701767??? 0 drwxrwxr-x?? 2 root???? mail????????? 105 Sep 17 07:19 /var/spool/mail
8.查找當前系統上沒有屬主或屬組的文件;
進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的目錄或文件;
[root@centos7 var]# find / \( -nouser -o -nogroup \) -atime +3 -ls
find: ‘/proc/7176/task/7176/fd/6’: No such file or directory
find: ‘/proc/7176/task/7176/fdinfo/6’: No such file or directory
find: ‘/proc/7176/fd/6’: No such file or directory
find: ‘/proc/7176/fdinfo/6’: No such file or directory
34754918??? 0 -rw-rw—-?? 1 1005???? mail??????????? 0 Sep? 2 11:28 /var/spool/mail/mandriva
18360951??? 4 -rw-r–r–?? 1 1005???? distro???????? 18 Aug? 2? 2016 /home/mandriva/.bash_logout
18360952??? 4 -rw-r–r–?? 1 1005???? distro??????? 193 Aug? 2? 2016 /home/mandriva/.bash_profile
18360953??? 4 -rw-r–r–?? 1 1005???? distro??????? 231 Aug? 2? 2016 /home/mandriva/.bashrc
34754923??? 4 -rw——-?? 1 1005???? distro???????? 11 Sep? 2 11:30 /home/mandriva/.cache/abrt/lastnotification
18360956??? 4 -rw——-?? 1 1005???? distro???????? 24 Sep? 2 12:13 /home/mandriva/.bash_history
9.查找/etc目錄下所有用戶都有寫權限的文件;
[root@centos7 etc]# find /etc/ -perm /222 -type f -ls
10. 查找/etc目錄下大于1M,且類型為普通文件的所有文件;
find /etc/ -size 1M? -type f -ls
?

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87385

(0)
469008940469008940
上一篇 2017-09-18 16:09
下一篇 2017-09-18 19:58

相關推薦

  • 第六周作業-Vim總結

                    Vim總結 vim功能比較多,這里我不總結vim多窗口,只對基本常用的介紹. 一.模式說明 vim和記事本或WORD不一樣,不是一打開后就可以輸入文字,此時它處于正常?!?/p>

    Linux干貨 2017-01-16
  • 磁盤管理及文件系統

    磁盤管理 本文將從以下幾方面介紹 第一部分:磁盤管理 1、淺識Linux磁盤 2、常見命令 第二部分:文件系統管理 1、文件系統的創建 2、文件系統掛載 3、自動掛載配置文件 第一部分:磁盤管理 淺識Linux磁盤 對于Linux來說我們知道一切皆文件,同樣在Linux中硬件設備在系統上會映射成相對應的文件,我們就像是在Windows看文件一樣只要打開對應的…

    Linux干貨 2017-08-15
  • 定時任務的完成contab

    采用crontab來完成 利用crontab來定時執行任務大致有如下三步: 1、編寫shell腳本 2、利用crontab加入到定時任務隊列 3、查看作業完成情況 一、如何建立shell腳本 Linux下有很多不同的shell,但我們通常使用bash(bourne again shell)進行編程,因為bash是免費的并且很容易使用 程序必須以下面的行開始(…

    Linux干貨 2016-08-11
  • btrfs管理及應用

    一、btrfs的命令選項     mkfs.btrfs         -L 'LABEL' 指定卷標         -d <type&…

    Linux干貨 2016-03-12
  • Linux網絡配置

    (1)、ifcfg家庭命令配置: ifconfig/route/netstat ifup/ifdown   (2)、ip命令配置: ip addr | route | link   (3)、修改配置文件 IP、MASK、GW、DNS相關配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE 路由相關…

    2018-01-30
  • 文本處理工具 練習

    7.1 練習   1 、找出ifconfig 命令結果中本機的所有IPv4 地址 2 、查出分區空間使用率的最大百分比值   3 、查出用戶UID 最大值的用戶名、UID 及shell 類型 4 、查出/tmp 的權限,以數字方式顯示   5 、統計當前連接本機的每個遠程主機IP 的連接數,并按從大到小排序   &nb…

    Linux干貨 2016-08-07
欧美性久久久久