# move to incoming/ so that we don't
# need to strip a path prefix
cd incoming
# create directories that are missing in archive
for d in `find . -type d`; do
if [ ! -d "../archive/$d" ]; then
mkdir -p "../archive/$d"
fi
done
# concatenate all files to already existing
# ones (or automatically create them)
for f in `find . -type f`; do
cat "$f" >> "../archive/$f"
done
This should find any file in incoming
and concatenate it to an existing file in archive
.
The important part is to be inside incoming
, because else we'd had to strip the path prefix (which is possible, but in the above case unnecessary). In the above case, a value of $f
typically looks like ./a/data.txt
, and hence the redirection goes to ../archive/./a/data.txt
.