There’s a section of code on Stack Exchange that I’m trying to manipulate. In the original scenario, it takes some user input and moves files of a certain age to another directory, whilst maintaining the directory structure:
destination=$(cd -- "$destination" && pwd) # make it an absolute path
cd -- "$source" &&
find . -type f -mtime "-$days" -exec sh -c '
for x do
mkdir -p "$0/${x%/*}"
mv "$x" "$0/$x"
done
' "$destination" {} +
How can I modify this so that it reads a list of files and moves them to another folder whilst maintaining the directory structure? The list of files is relative to the shell but I can make it absolute if necessary. I tried turning it into a read loop but it didn’t work, because I suck:
cd $sourcedir
sh -c '
while read x do
mkdir -p "$0/${x%/*}"
mv "$x" "$0/$x"
done
' <"$filesin" | tee -a "$filesout" >/dev/null