天天看點

find指令 檔案名字尾

 find指令

1、檢視目前目錄下以.txt結尾的檔案

[root@test ~]# find . -name "*.txt"

./.subversion/README.txt

./2.txt

./nmaptest.txt

./1.txt

    不是以.txt結尾的檔案查找:

[root@test ~]# find . ! -name "*.txt"| more

.

./.cshrc

./.subversion

./.subversion/servers

./.subversion/config

2、根據檔案類型查找

f 普通檔案 l 符号連接配接 d 目錄 c 字元裝置 b 塊裝置 s 套接字 p Fifo

[root@test ~]# find /tmp/ -type d -name mysql

/tmp/mysql

/tmp/mysql/mysql

3、根據檔案時間戳進行搜尋

Linux檔案系統每個檔案都有三種時間戳: 

通路時間(-atime/天,-amin/分鐘):使用者最近一次通路時間。 

修改時間(-mtime/天,-mmin/分鐘):檔案最後一次修改時間。 

變化時間(-ctime/天,-cmin/分鐘):檔案資料(例如權限等)最後一次修改時間。

[root@test ~]# stat 1.txt

  File: `1.txt'

  Size: 37        Blocks: 8          IO Block: 4096   regular file

Device: fd00h/64768dInode: 21749       Links: 2

Access: (0626/-rw--w-rw-)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-10-23 12:12:07.619932872 +0800#當檔案被通路時變化

Modify: 2017-10-23 14:36:12.180013439 +0800#當檔案被修改時變化

Change: 2017-10-23 14:36:12.192013624 +0800#當檔案被修改時變化

+2:2天以外的;-2:2天以内的;xargs:額外擴充

[root@test ~]# find . -ctime +2 -name "*.txt"|xargs ls -lt

-rw-r--r--  1 root root   4276 Oct 17 14:45 ./.subversion/README.txt

-rw-r--r--  1 root root   4821 Oct 11 04:12 ./setuptools-36.5.0/setuptools.egg-info/SOURCES.txt

-rw-r--r--  1 root root   2939 Oct 11 04:12 ./setuptools-36.5.0/setuptools.egg-info/entry_points.txt

 該目錄10分鐘之前被通路過的

[root@test ~]# find . -type f -amin +10 

You have new mail in /var/spool/mail/root

該目錄10分鐘之内被通路過的

[root@test ~]# find . -type f -amin -10 

4、根據檔案大小進行比對(K/M/G)

4.1 搜尋大于10KB的檔案

[root@test ~]# find . -type f -size +10k

./get-pip.py

./.bypy/bypy.hashcache.json

   小于10KB的檔案

[root@test ~]#  find . -type f -size -10k

5、借助-exec選項與其他指令結合使用

将".txt"結尾的檔案都删除

[root@test76 83-server]# find . -name '*.txt' -exec rm  {} \;

6、用到-o選項(兩個條件滿足一個即可);找出目前目錄下以.txt,.php結尾的檔案;

[root@test ~]# find . -name '*.php' -o -name '*.txt'

./123.txt

./index.php

用到-a選項;兩個條件同時滿足

[root@test ~]# find . -size +10k -a -size -100k|xargs du -sh

52K ./.cache/pip/http/2/e/a/f/9/2eaf9e7adb17e72f1ab2b6510f37425dc6772b

16K ./.cache/pip/http/9/e/6/1/9/9e61964f51d8a05a20ecf21eef694877f28cb

52K ./.cache/pip/http/c/e/8/8/0/ce880eded052487dc850e45bc

88K ./.cache/pip/http/d/f/6/b/4/df6b402f6800301aea4d1b04d0c

68K ./.cache/pip/http/e/8/a/4/5/e8a45d85bbef483

56K ./.cache/pip/http/f/c/9/f/0/fc9f0666469c64f19c

20K ./.pip/pip.log

32K ./.bash_history

檔案名字尾

file 檔案名

[root@~]# file test.sh 

test.sh: POSIX shell script text executable

.php  php解釋語言

.so             庫檔案

.bz2        bzip2的壓縮檔案

.gz            gzip的壓縮檔案

.tar            tar打封包件

.sh             shell腳本

.log           日志檔案

本文轉自 jiekegz  51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/1975241