Linux – Copy directory structure only at year end

bashlinuxunix

Happy New Year.
I have a solution to this, but I can't make it work unless I am in the directory I want to copy.

At the end of 2018, I want to copy the directory structure only of various folders named 2018/ into 2019/.

cd 2018/
find . -type d -exec mkdir -p ../2019/{} \;

And this works.
How do I do it from the base directory?

find 2018 -type d -exec basename {} \;

gives me the folder names, but

find 2018 -type d -exec mkdir 2019/`basename {}` \;

still copies the 2018 folder into the 2019 folder, and you loose the directory tree.

I can't find a simple answer after multiple searches. Any ideas?

Edit
Thanks for all the help and suggestions. This one ultimately worked best for me:

find 2018/* -type d | sed 's/^2018//g' | xargs -I {} mkdir -p 2019"/{}"

Best Answer

This like should do the trick:

for FOLDER in `ls -l 2018/|grep '^d'|awk '{print $9}'`; do mkdir -p 2019/$FOLDER; done

OR

for FOLDER in `find 2018 -type d -exec basename {} \;|grep -v 2018`; do mkdir -p 2019/$FOLDER; done

I hope this helps.