Copying a Directory Tree
I wanted to duplicate a directory tree without copying files. I did not recall needing to do that before. After my common habit of sleeping on the question I awakened with a simple approach.
find /toplevel/name/of/directory -type d
That output provided me the directories.
The output may be massageed as needed. For example:
OLD_IFS="$IFS"; IFS=$'\n'; for dir in $(find /toplevel/name/of/directory -type d | sort | sed -e ’s|/toplevel/||'); do echo “$dir"; mkdir -p “$dir"; done; IFS="$OLD_IFS"
The internal file separator (IFS) variables and quotation marks manage directory names containing spaces.
To compare the directory tree use tree -d
in each location.
Posted: Usability Tagged: General
Category:Next: My Desktop Computer Is Not a Mobile Device
Previous: Updating Slackware — 6