如何打印匹配grep模式的文件的文件细节 [英] How to print file details of files matching grep pattern
问题描述
我想打印文件的详细信息以及grep输出,但无法这样做。例如,对于命令
grep 3456 A.txt
我得到输出
A.txt
code>
但希望输出
-rw-rw-r-- 1 tarun tarun 41356911 Aug 25 01:31 A.txt
我尝试了以下方法但没有成功:
-
grep 34567 A.txt | xargs ls -tlr
-
grep 34567 A.txt |而读线;做回声$行|日期%s。%N;完成
-
grep -Hr 34567 A.txt | awk -F:'{stat -c%z$ 1 | getline r; print r:$ 0'
-
grep 34567 A.txt | awk -F:'{date -r \$ 1\+ \%F%R \| getline d; print d,$ 0}'
grep -Zl 3456 * | xargs -0 ls -l
使用GNU grep。这些选项包括:
grep -Z
和 xargs -0
:用NULL字节而不是空格分隔输出名称。这样你就可以处理包含空格的文件名。
grep -l </ code>:仅打印匹配的文件名
ls -l </ code>:标准
ls
长输出,这似乎就是您要求的。
测试最新的cygwin。
I want to print file details along with grep output but unable to do so. E.g., for the command
grep 3456 A.txt
I get the output
A.txt
but would like the output
-rw-rw-r-- 1 tarun tarun 41356911 Aug 25 01:31 A.txt
I tried the following without success:
grep 34567 A.txt | xargs ls -tlr
grep 34567 A.txt | while read line ; do echo "$line" | date %s.%N ; done
grep -Hr 34567 A.txt | awk -F: '{"stat -c %z "$1 | getline r; print r": "$0 }'
grep 34567 A.txt | awk -F: '{"date -r \""$1"\" +\"%F %R\"" | getline d; print d,$0}'
grep -Zl 3456 * | xargs -0 ls -l
with GNU grep. The options are:
grep -Z
andxargs -0
: separate output names by a NULL byte instead of by whitespace. This way you can handle filenames that include spaces.grep -l
: print only the filenames that matchls -l
: Standardls
long output, which appears to be what you are asking for.
Tested on latest cygwin.
这篇关于如何打印匹配grep模式的文件的文件细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!