I have a find command that selects some directories and files to be copied to a different location (with --parents). What I'd like is for the directories that are output by the find command to be copied without contents (but they should have the same ownership and mode).I could limit find to files only with -type f or ! -type d, but then directories would be created as needed with the default ownership and mode. If I use the -r option to cp, then directories are copied with the right ownership and mode, but also with all their files. Basically, I'd like for directories in the listing to result in copying only the directory metadata without its contents.How to achieve this?
How to copy files and directories without copying directory contents?
find;cp
The simplest tool to use I think is pax, as it has a -d option which says not to recurse when given a directory.So to copy just directories, doing it in steps, so you can validate that the directories are copied do not copy the files as well you can dofind somewhere -type d | pax -wd  > archive.tartar vtf archive.tar( cd somewhere_else && tar xpf - ) < archive.tarOnce you are happy, you can remove the intermediate printing of the contents of the archive (the tar vxf archive.tar) and replace the intermediate archive.tar file with a pipe.