查找字符串

本身不难,写到这里只是一个备忘录的作用。

假定Linux系统中有一个目录,其中递归的存在若干子目录。现在需要在这些目录的文件中寻找一个字符串marvel。

我看到的方法是 find -type f -exec grep marvel {};

可是死活就是错误: find: missing argument to `-exec’

后来才发现,原来是 find -type f -exec grep marvel {};

分号需要进行转义的。同理如果在c文件中寻找,则改为 find -name *.c -exec grep marvel {};

如果要删除全部c文件则用 find -name *.c -exec rm {};

Leave a Reply

Your email address will not be published. Required fields are marked *