[英]Sort a find command by date
我有一個腳本:
newerthan="2016-02-08"
olderthan="2016-04-29"
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -ls
此列表文件:
16481 0 -r--r--r-- 1 root root 4096 Mar 16 11:41 /sys/module/sunrpc/srcversion
16482 0 -r--r--r-- 1 root root 4096 Mar 13 04:42 /sys/module/sunrpc/initstate
16483 0 -r--r--r-- 1 root root 4096 Mar 16 11:41 /sys/module/sunrpc/refcnt
16485 0 -r--r--r-- 1 root root 4096 Mar 17 11:41 /sys/module/sunrpc/sections/.note.gnu.build-id
16486 0 -r--r--r-- 1 root root 4096 Mar 12 11:41 /sys/module/sunrpc/sections/.text
是否可以按日期,結果排序?
這將返回按日期排序,受時間戳限制的列表,其中顯示文件名
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf '%T@ %p\n' | sort -k 1 -n | sed 's/^[^ ]* //'
如果需要其他列,則可以更改printf和sort參數以顯示更多列,並按位置而不是按列排序
如果要按排序順序打印文件名和日期:
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf "%T+\t%p\n" | sort
如果只想按排序順序打印文件名:
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf "%T+\t%p\n" | sort | awk '{print $2}'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.