I've 2 folders. Folder 1 has some files arranged in some sub folders. Folder 2 has same-filenamed-files (but different size) but not arranged in any sub folder. I want to arrange folder 2 files like folder 1. Is there a quick way to do that? I'm using Linux.
Asked
Active
Viewed 63 times
-1
1 Answers
0
Mayhap something along these lines will do:
cd "$folder1"
echo "mkdir -p " $(find . -type d | tee /tmp/dirs) > /tmp/tmpscript
find . | awk -F"/" 'FNR == NR {DIR[$0]; next} !($0 in DIR) && !(NF == 2) {print "cp \"" $NF "\" \"" $0"\""}' /tmp/dirs - >> /tmp/tmpscript
cd "$folder2"
less /tmp/tmpscript
# rm /tmp/dirs /tmp/tmpscript
It creates a temporary script that first creates the subdirectory structure under folder2, then cps every single file from there into its pertaining subdir. Change cp to mv if need be. Scrutinize the tmpscript first (with e.g. less) before actually running it. As a last step, the temp files should be removed. No effort has been done to optimize the copying action; every single file is handled on its own. Improvements could be done like collecting all files bound to one subdir into one copy command.
RudiC
- 8,969
treecommand? – RudiC Apr 14 '22 at 18:19