使用 cat 写入多个文件

使用 cat 写入多个文件

我有一些想要写入的空 html 文件。我正在尝试这个

cat account_settings/account_settings.html >> assets/assets.html, users/users.html

尝试写入文件assets.htmlusers.html

我如何写入多个文件?

答案1

您可以使用tee命令

NAME
       tee - read from standard input and write to standard output and files

例如

cat account_settings/account_settings.html | tee -a assets/assets.html users/users.html

或(使用输入重定向)

tee -a assets/assets.html users/users.html < account_settings/account_settings.html

如手册页所述,tee还将内容输出到终端(标准输出) - 如果您不想看到它,请将 stdout 重定向为 null

tee -a assets/assets.html users/users.html < account_settings/account_settings.html > /dev/null

答案2

只需循环遍历所需文件列表

for file in assets/assets.html users/users.html
do
    cat account_settings/account_settings.html >> "$file"
done

相关内容