<form id="dlljd"></form>
        <address id="dlljd"><address id="dlljd"><listing id="dlljd"></listing></address></address>

        <em id="dlljd"><form id="dlljd"></form></em>

          <address id="dlljd"></address>
            <noframes id="dlljd">

              聯系我們 - 廣告服務 - 聯系電話:
              您的當前位置: > 關注 > > 正文

              精選!find命令詳解 linux下find命令的使用方法

              來源:CSDN 時間:2023-03-10 14:58:44

              find命令


              【資料圖】

              一般格式: find  +  目錄名稱  +  參數

              @1參數的含義:-name           #文件名稱

              實驗1:按照文件名查找

              ##查找/etc目錄中文件名為passwd的文件[root@localhost ~]# find /etc/ -name passwd/etc/passwd/etc/pam.d/passwd##查找/etc目錄中文件名以.conf文件結尾的文件[root@localhost mnt]# find /etc/ -name *.conf

              @2參數含義:-not            #非,取反-user           #文件所有人-group          #文件所有組-a              #并且關系-o              #或者關系

              實驗2:按文件所有人和文件所有組查找

              [root@localhost ~]# cd /mnt##建立文件[root@localhost mnt]# touch file{1..5}[root@localhost mnt]# lsfile1  file2  file3  file4  file5

              監控:

              [root@localhost mnt]# watch -n 1 ls -l /mnt

              [root@localhost ~]# id studentuid=1000(student) gid=1000(student) groups=1000(student),10(wheel)[root@localhost ~]# id westosuid=1001(westos) gid=1001(westos) groups=1001(westos)##更改文件的所有人和所有組[root@localhost ~]# chown student.student /mnt/file1##更改文件的所有組[root@localhost ~]# chgrp westos /mnt/file2[root@localhost ~]# chown student.westos /mnt/file3

              ##按文件的所有人查找[root@localhost ~]# find /mnt -user student /mnt/file1/mnt/file3##按文件的所有組查找[root@localhost ~]# find /mnt -group westos/mnt/file2/mnt/file3##默認表示并且[root@localhost ~]# find /mnt -user root -group westos/mnt/file2## -a表示并且[root@localhost ~]# find /mnt -user root -a -group westos/mnt/file2## -o表示或者[root@localhost ~]# find /mnt -user root -o -group westos/mnt/mnt/file2/mnt/file3/mnt/file4/mnt/file5## -not表示非;即反向選擇[root@localhost ~]# find /mnt -not -user student /mnt/mnt/file2/mnt/file4/mnt/file5

              @3參數含義:-maxdepth       #最大深度-mindepth       #最小深度

              實驗3:按文件所在的深度(層次)查找

              ##-maxdepth表示最大深度,即最多層次[root@localhost ~]# find /etc/ -maxdepth 1 -name passwd/etc/passwd[root@localhost ~]# find /etc/ -maxdepth 2 -name passwd/etc/passwd/etc/pam.d/passwd##-mindepth表示最小深度,即最少層次[root@localhost ~]# find /etc/ -mindepth 2 -name passwd/etc/pam.d/passwd[root@localhost ~]# find /etc/ -mindepth 1 -name passwd/etc/passwd/etc/pam.d/passwd##查找/etc目錄下最少層次為1最多層次為2的以.conf結尾的文件[root@localhost ~]# find /etc/ -mindepth 1 -maxdepth 2 -name *.conf

              @4參數含義:   -size 表示文件大小     -size  20K      # 查找大小為20K的文件     -size  -20K     # -表示小于;查找比20K小的文件     -size  +20k     # +表示大于;查看比20K大的文件

              實驗4:按文件的大小查找

              [root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##dd表示截取,if輸入,of輸出[root@localhost mnt]# dd if=/dev/zero of=file1 bs=1 count=1024010240+0 records in10240+0 records out10240 bytes (10 kB) copied, 0.0113629 s, 901 kB/s##查看文件所占磁盤的大小[root@localhost mnt]# du -sh file112Kfile1[root@localhost mnt]# dd if=/dev/zero of=file2 bs=1 count=2048020480+0 records in20480+0 records out20480 bytes (20 kB) copied, 0.0198726 s, 1.0 MB/s[root@localhost mnt]# du -sh file220Kfile2[root@localhost mnt]# dd if=/dev/zero of=file3 bs=1 count=4096040960+0 records in40960+0 records out40960 bytes (41 kB) copied, 0.0397736 s, 1.0 MB/s[root@localhost mnt]# du -sh file340Kfile3

              [root@localhost mnt]# ll -ltotal 72-rw-r--r--. 1 root root 10240 Nov 11 04:06 file1-rw-r--r--. 1 root root 20480 Nov 11 04:06 file2-rw-r--r--. 1 root root 40960 Nov 11 04:06 file3##查找/mnt目錄下文件大小為20k的文件[root@localhost mnt]# find /mnt/ -size 20k/mnt/file2##查找/mnt目錄下比20k小的文件[root@localhost mnt]# find /mnt/ -size -20k/mnt//mnt/file1##查找/mnt目錄下比20k大的文件[root@localhost mnt]# find /mnt/ -size +20k/mnt/file3

              @5參數含義:-type         #文件類型主要的文件類型:     f        #普通文件     d        #目錄     b        #塊設備     s        #套接字     c        #字符設備     l        #鏈接     p        #管道

              實驗5:按文件類型查找

              ##f表示普通文件[root@localhost ~]# find /dev -type f/dev/shm/pulse-shm-620843697/dev/shm/pulse-shm-1247103260/dev/shm/pulse-shm-2690706600/dev/shm/pulse-shm-368331657##b表示塊設備[root@localhost ~]# find /dev -type b/dev/dm-0/dev/sr0/dev/vdb1/dev/vdb/dev/vda1/dev/vda##s表示套接字[root@localhost ~]# find /dev -type s/dev/log##p表示管道[root@localhost ~]# find /dev -type p/dev/initctl[root@localhost ~]# find /mnt -type f/mnt/file1/mnt/file3/mnt/file2##d表示目錄[root@localhost ~]# find /mnt -type d/mnt

              @6參數含義:-perm  表示權限-perm  444       #查找文件權限-perm  -444      # -表示并且;查找文件權限中u位有r權限,并且g位有r權限,并且o位有r權限的文件-perm  /444      # /表示或者;查找文件權限中u位有r權限,或者g位有r權限,或者o位有r權限的文件-perm  /777      # 777=rwx rwx rwx 即9個條件中滿足任意一個即可

              實驗6:按文件權限查找

              [root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##建立文件[root@localhost mnt]# touch file{1..3}[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 09:41 file1-rw-r--r-- 1 root root 0 Nov 14 09:41 file2-rw-r--r-- 1 root root 0 Nov 14 09:41 file3##更改文件權限[root@localhost mnt]# chmod 777 /mnt/file1[root@localhost mnt]# chmod 404 /mnt/file2[root@localhost mnt]# chmod 400 /mnt/file3[root@localhost mnt]# lltotal 0-rwxrwxrwx 1 root root 0 Nov 14 09:41 file1-r-----r-- 1 root root 0 Nov 14 09:41 file2-r-------- 1 root root 0 Nov 14 09:41 file3

              ##查找文件權限為404的文件[root@localhost mnt]# find /mnt -perm 404/mnt/file2##查看文件權限中u位有r權限,并且o位有r權限的文件[root@localhost mnt]# find /mnt -perm -404/mnt/mnt/file1/mnt/file2##查看文件權限中u位有r權限,或者o位有r權限的文件[root@localhost mnt]# find /mnt -perm /404/mnt/mnt/file1/mnt/file2/mnt/file3[root@localhost mnt]# ll -d /mnt/drwxr-xr-x. 2 root root 42 Nov 14 09:41 /mnt/

              @7參數含義:ctime 與 cmin 都表示按照時間查找被篡改的文件ctime   ##以天為單位cmin    ##以分鐘為單位 -cmin  10         #查找文件更新距離現在10分鐘的文件-cmin  +10        #查找文件更新距離現在超過10分鐘的文件-cmin  -10        #查找文件更新距離現在10分鐘以內的文件-ctime  +/-10     #查找文件更新距離現在超過10天/10天以內的文件

              實驗7:按文件更新的時間

              [root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##建立文件[root@localhost mnt]# touch file{1..3}##查找文件更新距離現在為1分鐘的文件[root@localhost mnt]# find /mnt/ -ctime 1##查找文件更新距離現在為1分鐘以內的文件[root@localhost mnt]# find /mnt/ -ctime -1/mnt//mnt/file1/mnt/file2/mnt/file3##查找文件更新距離現在超過1分鐘的文件[root@localhost mnt]# find /mnt/ -ctime +1

              參數含義:-exec   命令  {}   \;      #對查找到的文件執行某命令;-exec表示開始執行動作  {} 表示用find命令查找出的所有文件

              實驗8:對查找到的文件執行某些動作

              (1).給/mnt下文件權限包含004的文件的g位加w的權限

              [root@localhost mnt]# pwd/mnt[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-rw-r--r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##更改權限[root@localhost mnt]# chmod 404 /mnt/file2[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r-----r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##給/mnt下文件權限包含004的文件的g位加w的權限[root@localhost mnt]# find /mnt -perm 404 -exec chmod g+w {} \;[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3

              (2).將系統中屬于mail組的文件備份到/mnt下

              [root@localhost ~]# ll /mnttotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##將系統中屬于mail組的文件備份到/mnt下[root@localhost ~]# find / -group mail -exec cp {} /mnt \;find: ‘/proc/6812/task/6812/fd/6’: No such file or directoryfind: ‘/proc/6812/task/6812/fdinfo/6’: No such file or directoryfind: ‘/proc/6812/fd/6’: No such file or directoryfind: ‘/proc/6812/fdinfo/6’: No such file or directorycp: omitting directory ‘/var/spool/mail’[root@localhost ~]# ll /mnttotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3-rw-r----- 1 root root 0 Nov 14 10:14 rpc-rw-r----- 1 root root 0 Nov 14 10:14 student-rw-r----- 1 root root 0 Nov 14 10:14 westos

              責任編輯:

              標簽:

              相關推薦:

              精彩放送:

              新聞聚焦
              Top 中文字幕在线观看亚洲日韩