有没有办法使用 CLI 将 README.txt 文件从 /root 复制到每个 /home/{USER}/public_html 目录中?
答案1
使用(假设是 BASH):
pushd /home;
for file in ./*; do
cp /root/README.txt /home/$file/public_html/
chown $file /home/$file/public_html/README.txt
# this is a cheat, assuming that every user's name equals his home directory
done;
popd
答案2
独立于 Shell,您可以使用“find”如下...
find /home -name public_html -maxdepth 2 -exec cp /root/README.html {} \;