I needed a simple script that would copy the entire folder structure of certain users (under Linux) to a backup destination. This is how I did it.
You would need a file call users.txt with the names of the users, divided by linebreaks.
users.txt:
user1
user2
user3
And this little script:
createfolders.sh:
#!/bin/sh
dest='/backup'
cat users.txt | while read user;
do
base="/users/$user"
find $base -type d -print | cpio -pvdum $dest
done
Cool, but why the “cpio”?
—
Giu
It was the only option that successfully copied all folders, even with spaces or special characters in their name. Tried rsync and cc but it always bombed out.
I see, and I can’t “nitpick” over anything since any other method I can think of involves a nested while loop. And, IIRC, “tar” syntax is more verbose than cpio’s… Hence: you win. 🙂