Append file A.txt to file B.txt located in all subdirectories in linux command line [closed]

六眼飞鱼酱① 提交于 2019-12-24 21:56:18

问题


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'''


回答1:


Like this:

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

or

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

or

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


来源:https://stackoverflow.com/questions/59307184/append-file-a-txt-to-file-b-txt-located-in-all-subdirectories-in-linux-command-l

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!