linux – grep输出文件路径与文件修改日期?
发布时间:2020-12-14 02:44:35 所属栏目:Linux 来源:网络整理
导读:是否可以使grep命令输出文件修改日期的文件路径,如下所示: 12-02-2015 /file/path/to/the/file16-02-2015 /file/path/to/the/file25-02-2015 /file/path/to/the/file03-04-2015 /file/path/to/the/file 要么: /file/path/to/the/file 12-02-2015/file/path
是否可以使grep命令输出文件修改日期的文件路径,如下所示:
12-02-2015 /file/path/to/the/file 16-02-2015 /file/path/to/the/file 25-02-2015 /file/path/to/the/file 03-04-2015 /file/path/to/the/file 要么: /file/path/to/the/file 12-02-2015 /file/path/to/the/file 12-02-2015 /file/path/to/the/file 12-02-2015 /file/path/to/the/file 12-02-2015 解决方法
grep本身没有功能.但你可以使用awk.使用该语法:
grep -Hr pattern . | awk -F: '{"stat -c %z "$1 | getline r; print r": "$0 }' 这迫使grep打印文件名-H. -r表示在给定目录中搜??索recusive .. awk的字段分隔符设置为:.第一个varibale $1现在包含文件名. awk在每个文件名上调用stat -c%z,以人类可读的格式给出修改时间.它被保存到变量r中,变量r打印在每个搜索结果的前面. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |