使用 cat 写入多个文件

Le *_* Qs 7 command-line bash

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

cat account_settings/account_settings.html >> assets/assets.html, users/users.html
Run Code Online (Sandbox Code Playgroud)

尝试写入文件assets.htmlusers.html.

如何写入多个文件?

ste*_*ver 14

你可以使用tee命令

NAME
       tee - read from standard input and write to standard output and files
Run Code Online (Sandbox Code Playgroud)

例如

cat account_settings/account_settings.html | tee -a assets/assets.html users/users.html
Run Code Online (Sandbox Code Playgroud)

或(使用输入重定向)

tee -a assets/assets.html users/users.html < account_settings/account_settings.html
Run Code Online (Sandbox Code Playgroud)

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

tee -a assets/assets.html users/users.html < account_settings/account_settings.html > /dev/null
Run Code Online (Sandbox Code Playgroud)


Ser*_*nyy 6

只需循环你想要的文件列表

for file in assets/assets.html users/users.html
do
    cat account_settings/account_settings.html >> "$file"
done
Run Code Online (Sandbox Code Playgroud)