linux命令find粗略用法

2021-09-25 18:55:47 字數 2297 閱讀 9518

find基本用法

單一匹配:find [查詢目錄] [引數] [匹配模型]

多引數匹配:find [查詢目錄] [引數] [匹配模型] [引數] [匹配模型]  

1、find . -name "*.sh"  

根據檔名過濾

2、find . -user root    

根據使用者過濾

3、find . -perm 755 

根據許可權過濾

4、find . -size +1000000c 

根據檔案大小過濾

+大於,-小於,c位元組 b:block(512位元組) w:two-byte words k:kilobytes(1024位元組)

6、find ./desktop  -type f  -newermt '2019-07-01 00:00:00'

查詢桌面上2019-07-01以後更新過的檔案

-newermt是-newerxy引數的一種,

x可以為abcm,a:access b:birth c:change m:modify,不是所有系統都支援b引數,慎用

y一般為t,表示時間

find命令只會顯示檔案路徑,不會顯示檔案具體資訊,ls -l可以顯示相對的全路徑和具體資訊,兩者通過xargs結合使用

find ./desktop  -type f  -newermt '2019-07-01 00:00:00' -size +1000c | xargs ls -l --time-style '+%y-%m-%d'

-rw-r--r-- 1 root  root    3580 2019-08-01 ./desktop/a.txt

-rw-r--r-- 1 root  root    3900 2019-07-27 ./desktop/hello-world-1.1-1.el7.x86_64.rpm

-rwxrwxrwx 1 root  root    1328 2019-07-24 ./desktop/testcmd.1

如上顯示桌面上2019-07-01以後更新過的大於1000位元組的檔案

ls也可以換成rm,刪除指定時間的檔案,

反向過濾

!

find ./desktop  -type f ! -newermt '2019-07-01 00:00:00' -size +1000c | xargs ls -l --time-style '+%y-%m-%d'

-rw-r--r-- 1 root  root   88308 2019-04-13 ./desktop/5.sql

-rwxrwxrwx 1 root  root    1809 2019-04-12 ./desktop/addd.sh

-rw-r--r-- 1 root  root    1074 2019-04-12 ./desktop/dump.rdb

-rw-rw-r-- 1 king king   1351 2019-05-15 ./desktop/test.go

-rw-r--r-- 1 root  root  100963 2019-06-14 ./desktop/test.sql

如上顯示桌面上在2019-07-01以前最後更新過的大於1000位元組的檔案

find ./desktop  -type f -newermt '2019-05-01 00:00:00' ! -newermt '2019-07-01' -size +1000c | xargs ls -l --time-style '+%y-%m-%d'

-rw-rw-r-- 1 king king 1351 2019-05-15 ./desktop/test.go

-rw-r--r-- 1 root  root  100963 2019-06-14 ./desktop/test.sql

如上顯示桌面上在2019-05-01到2019-07-01之間最後更新過的大於1000位元組的檔案

使用find -exec引數結合其他命令

find ./desktop  -type f -newermt '2019-06-01 00:00:00' ! -newermt '2019-07-01' -size +1000c -exec ls -l {} \;

{}就是一條路徑,後面接空格,反斜線,分號,看起來怪怪的,還沒xargs好理解

ls使用--time-style自定義時間顯示格式

ls -l --time-style long-iso ./desktop/

ls -l --time-style '+%y-%m-%d %h:%m:%s.%s' ./desktop/

find 排除 Linux 命令之 find 用法

1.概述 使用linux server命令列系統時,經常需要進行特定檔案的查詢,主要的查詢命令是find及grep,區別如下 1.1 find 根據檔案屬性進行查詢,如檔名 檔案大小 檔案所有者 訪問時間 修改時間 是否為空等 1.2 grep 根據檔案內容查詢,會對檔案的每一行按照給定的模式進行匹...

Linux中find命令用法

linux下的find命令,顧名思義,它是在目錄結構中搜尋檔案,並執行指定的操作。linux下find命令提供了相當多的命令引數,也就是以何種條件進行查詢。命令格式 find 路徑 命令引數 表示式 預設路徑是當前路徑,預設表示式是 print print 將查詢到的檔案輸出到標準輸出 例如 在終端...

find命令用法

關於查詢 檔案查詢 locate非實時查詢 根據索引查詢 find實時查詢 根據檔案的各種屬性去找到相對應檔案 根據檔案的各種屬性去找到相對應檔案 文字搜尋 grep,egrep,fgrep find的用法 查詢條件 檔名類 使用者和組類 檔案型別 大小和時間 根據許可權查詢 組合條件查詢 處理動作...