【问题标题】:use file comand instead of -name使用文件命令而不是 -name
【发布时间】:2015-03-28 18:08:56
【问题描述】:

我想编写一个 shell 脚本,在所有 .txt 文件中搜索单词 cat 并将其替换为 mouse。我编写了以下代码:

!/bin/bash

read directory

for F in ` find $directory -name '*.txt' -type f`
    do
    echo $F
    `sed -i "s/\<cat\>/mouse/g" $F`
    done

我应该使用“文件”命令。我搜索了它,似乎文件命令找到了某种类型的所有文件。我想知道如何在我的脚本中包含该命令。

【问题讨论】:

  • 您能否edit 提出您的问题并解释您要对file 做什么?

标签: bash file shell find


【解决方案1】:

假设您位于所有 *.txt 文件所在的目录中。您可以执行以下命令:

find . -name *.txt -exec sed -i "s/\<cat\>/mouse/g" "{}" \;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多