16.12.10

Copy Directory Tree Without Files (and optionally files in some of the directories)

This will copy the directory tree under the input dir to the current dir (the dir the script is run from.


#!/bin/bash

for dir1 in $(find $1 -type d)
do
dir2=${dir1/$1/"")
mkdir -p .$dir2
done


This is if you want files to be copied from one of those dir's, in my case any dir named "fileparts".
#!/bin/bash

for dir1 in $(find $1 -type d)
do
dir2=${dir1/$1/""}
arDir1=(`echo $dir1| tr "/" "\n"`)

mkdir -p .$dir2

if [[ "${arDir1[${#arDir1[@]}-1]}" =~ "fileparts" ]] && [[ ! -z `ls $dir1/*` ]]
then
cp $dir1/* .$dir2
fi
done
http://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-tree-without-files-in-it-159404/

No comments: