[英]How to print file details of files matching grep pattern
I want to print file details along with grep output but unable to do so. 我想打印文件详细信息以及grep输出但无法这样做。 Eg, 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. 用GNU grep。 The options are:
选项是:
grep -Z
and xargs -0
: separate output names by a NULL byte instead of by whitespace. grep -Z
和xargs -0
:用NULL字节而不是空格分隔输出名称。 This way you can handle filenames that include spaces. grep -l
: print only the filenames that match grep -l
:只打印匹配的文件名 ls -l
: Standard ls
long output, which appears to be what you are asking for. ls -l
:标准ls
长输出,这似乎是你要求的。 Tested on latest cygwin. 测试了最新的cygwin。
There isn't need for xargs
here; 这里不需要
xargs
; find
can be used to both run grep
and run ls
, or even to emit ls
-style output itself. find
既可用于运行grep
,也可用于运行ls
,甚至可用于发出ls
style输出本身。
find . -maxdepth 1 -type f \
-exec grep -q -e '1234567' -- '{}' ';' \
-exec ls -l {} +
...or, even better: ......或者,甚至更好:
find . -maxdepth 1 -type f \
-exec grep -q -e '1234567' -- '{}' ';' \
-ls
The -ls
action uses an output format akin to ls -l
. -ls
动作使用类似于ls -l
的输出格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.