如何在 OSX 上指定 find 指令的日期範圍?

如何在 OSX 上指定 find 指令的日期範圍?

我需要查找日期範圍內精確到分鐘的文件。我想有一天知道如何做到這一點可能會有所幫助。無論如何。我已經學會如何使用 -newermt 甚至 -not -newermt;但是,當我將它們組合起來時,我似乎無法得到正確的結果。我找到了使用 find 的 linux 範例,但不認為這些開關在 OSX 上工作。請參閱以下文件清單:

#$ ls -l
total 32
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test1.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test1_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test2.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test2_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test3.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test3_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test4.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test4_old.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 20:11 test5.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 20:13 test6.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 timestamp.tmp

我希望以下命令透過 test4.swc 返回 test1.swc;但是,請注意它回傳了 test6.swc:

#$ find . -newermt '2010-10-26 20:11' -a -not -newermt '2010-10-26 20:13'
./test1.swc
./test2.swc
./test3.swc
./test4.swc
./test6.swc

我認為 -not 條件的分鐘已關閉,所以我嘗試了以下操作,但它什麼也沒返回:

#$ find . -newermt '2010-10-26 20:11' -a -not -newermt '2010-10-26 20:12'
#$ 

我得出的結論是,我沒有正確組合 -newermt 和 -not -newermt 開關。關於如何糾正這個問題有什麼建議嗎?

答案1

你的語法看起來是正確的。您是如何建立這些文件的。當我僅使用觸摸更新日期時,我看到了錯誤的返回。

在 BSD 中 -a 不是必需的,我傾向於使用 !而不是-not(個人喜好)

搜尋命令幫助時記得要搜尋BSD,因為我使用的有一些差異FreeBSD 手冊頁

請記住,文件上有超過分鐘的內容,因此如果您想要第一秒,則需要對其進行標記。我設定了一個像您一樣的結構,當我添加 :00 秒時,我可以獲得與您相同的結果,但它沒有意義。所以我做了一個 ls -lT 並能夠看到文件上的秒數,然後運行 find 命令並得到我的預期結果,默認情況下看起來像! or -not 將秒設為 59,因此它包括整分鐘。

#$ 找到 . -newermt「2010-10-26 20:11:00」! -newermt“2010-10-26 20:13:00”

相關內容