linux - 按日期排序查找命令

标签 linux bash find ls

我有一个脚本:

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+\t%p\n" | sort

如果只想按排序顺序打印文件名:

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

关于linux - 按日期排序查找命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36943314/

相关文章:

c - 有循环的 Stty 错误,没有循环没有 stty 错误

php - 有没有办法撤消 #kill `cat/mysql-data-directory/mysqld.pid` ?

bash - 创建非线性管道的最干净的方法是什么?

c# - 当按我搜索的字段排序时,我可以更快地搜索排序的 List<T> 吗?

linux - 如果 TOTAL CPU 小于 1%,则使用 monit 重启 ffmpeg 进程

Python循环下载多个文件

linux - 分别对每个文件进行 GZip

bash - 防止 bash vi 多行崩溃

Bash 脚本 : Use of date in foldername for calculation (Delete folders older than X)

linux - 在 Linux 中使用 Tail 递归地输出到单独的文件中