Copy files and directories without files content

Solution 1:

From man cp

--attributes-only don't copy the file data, just the attributes

So , if you want to copy all folders and files that are in somedirectory

do cp -R --attributes-only somedirectory destinationdirectory

Solution 2:

Nice that Ubuntu cp has this feature, but if you should find yourself on a machine that doesn't (BSD-style cp does not, for example, so OS X does not either), it's very easy to do with find. Here it is as a two-liner (for readability):

% cd original_dir
% find . -type d -exec mkdir -p ../copy_dir/{} \;
% find . -type f -exec touch ../copy_dir/{} \;

If copy_dir already exists, you can skip the -p argument to mkdir since find will traverse the directory tree top-down. For large jobs, you can shave off another millisecond or so by terminating the commands with + instead of \; if your find supports it (it probably does).

Edit: The above commands neglected to handle symbolic links, which can be copied with a third run of find (do not terminate this one with +):

% find . -type l -exec cp -R {} ../copy_dir/{} \;