问题
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