将文件A.txt附加到Linux命令行中所有子目录中的文件B.txt [英] Append file A.txt to file B.txt located in all subdirectories in linux command line

查看:197
本文介绍了将文件A.txt附加到Linux命令行中所有子目录中的文件B.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Linux命令行遍历当前目录中的所有文件并将文件A.txt附加到文件B.txt?文件A.txt位于当前目录中。文件B.txt在当前目录的所有子目录中位于多次。如果我只想做一次,我可以做'''cat A.txt >> B.txt'''

How to go through all files in the current directory and append file A.txt to file B.txt by Linux command line? File A.txt is located in the current directory. File B.txt is located multiple times in all subdirectories in the current directory. If I wanted to do it only once, I can do '''cat A.txt >> B.txt'''

推荐答案

例如:

find . -type f -name 'B.txt' -exec bash -c 'cat A.txt >> "$1"' -- {} \;

shopt -s globstar
for file in **/B.txt; do
    cat A.txt >> "$file"
done

find . -type f -name 'B.txt' -print0 | xargs -0 -I% sh -c 'cat A.txt > %'

这篇关于将文件A.txt附加到Linux命令行中所有子目录中的文件B.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆