寻找通用方法如何按修改时间对文件的随机列表进行排序,如下所示:
./make_list_of_files | some_sorter_by_mtime
Run Code Online (Sandbox Code Playgroud)
我现在的解决方案是(这make_list_of_files是find命令):
find / -type f -print |\
perl -nle 'push @in,$_;END {@out = sort{ (stat($a))[9] <=> (stat($b))[9] } @in; $,="\n";print @out}'
Run Code Online (Sandbox Code Playgroud)
存在一些更简单的解决方案(例如没有perl)?
你的some_sorter_by_mtime应该是例如:
xargs stat -f "%m %N" | sort -n | cut -f2-
Run Code Online (Sandbox Code Playgroud)
背后的想法是:
所以,
find / -type f -print | xargs stat -f "%m %N" | sort -n | cut -f2-
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
244 次 |
| 最近记录: |