如何对目录中的所有文件执行grep操作? [英] How to perform grep operation on all files in a directory?

查看:48
本文介绍了如何对目录中的所有文件执行grep操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用xenserver,我想对目录中的每个文件执行一条命令,从命令输出中提取一些内容并将其附加到文件中.

Working with xenserver, and I want to perform a command on each file that is in a directory, grepping some stuff out of the output of the command and appending it in a file.

我清楚要使用的命令以及如何根据需要grep输出字符串.

I'm clear on the command I want to use and how to grep out string(s) as needed.

但是我不清楚的是我如何在每个文件上执行此命令,然后转到下一个,直到找不到更多文件.

But what I'm not clear on is how do I have it perform this command on each file, going to the next, until no more files are found.

推荐答案

grep $ PATTERN * 就足够了.默认情况下,grep会跳过所有子目录.但是,如果要通过它们进行grep操作,请使用 grep -r $ PATTERN * .

grep $PATTERN * would be sufficient. By default, grep would skip all subdirectories. However, if you want to grep through them, grep -r $PATTERN * is the case.

这篇关于如何对目录中的所有文件执行grep操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆