是否可以使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
Run Code Online (Sandbox Code Playgroud)
或者:
/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
Run Code Online (Sandbox Code Playgroud)
grep本身没有功能。但是您可以使用awk. 使用该语法:
grep -Hr pattern . | awk -F: '{"stat -c %z "$1 | getline r; print r": "$0 }'
Run Code Online (Sandbox Code Playgroud)
这会强制grep打印文件名-H。-r表示在给定目录中搜索递归.。awk的字段分隔符设置为:. 第一个变量$1现在包含文件名。awk调用stat -c %z每个文件名,以人类可读的格式给出修改时间。这将保存到变量中r,该变量打印在每个搜索结果的前面。