2016-04-29 45 views
1

命令我有一个脚本:排序找到日期

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 

是否可以按日期排序,结果呢?

+1

试试这个:[?我如何使用'find'和修改时间对结果进行排序(http://unix.stackexchange.com/questions/29899/how-can-i-use - 查找和排序结果的mtime) –

回答

1

如果你要打印的文件名与有序日期进行:

find/-type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf "%T+\t%p\n" | sort 

如果你想只打印sorte文件名d命令:

find/-type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf "%T+\t%p\n" | sort | awk '{print $2}' 
+1

如果你想颠倒顺序:使用'sort -r'而不是'sort'。 – RaviTezu

1

这将返回排序的日期,时间戳限制,列表显示文件名

find/-type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf '%[email protected] %p\n' | sort -k 1 -n | sed 's/^[^ ]* //' 

如果你需要那些等栏目,你可以改变的printf和排序参数表现出更多的列和排序位置,而不是由列