I need to move a list of directories (and all their contents) from one location to another whilst preserving the tree structure. As an example I need to move:
As I need to process a list of folders I’ve tried to automate this using a bash script:
#!/bin/bash # populate ./dirstomove.list with a list of folders you want moved into target folder # dirstomove=./dirstomove.list clear echo "Files to process: " $(wc -l $dirstomove) echo "" while [ -s $dirstomove ] ; do currentdirtomove=$(head -1 $dirstomove) echo $currentdirtomove > /tmp/currentdirtomove sed 's|^.........||' /tmp/currentdirtomove > /tmp/targetdir targetdir=/mnt/sda1/needstagging`cat /tmp/targetdir` echo $targetdir # now move currentdirtomove to targetdir # mv "/$currentdirtomove" "$targetdir" # remove current file from list sed -i.prev '1d' $dirstomove done
The part I’m not sure of is how to get the full directory path moved. Any tips?