I'd like to duplicate the directory structure in some directory to another, without copying any actual files. In place of the files, I'd like either a blank file with the same name, or a symlink to the original location.

How could I do this, on OS X? Command-line tools (rsync/find/tar/whatever), shell scripts, etc., are all acceptable, software I have to buy probably isn't.

5 Answers 5

user@osx:~/from$ find . -type d -exec mkdir -p ~/to/{} \;
user@osx:~/from$ find . -type f -exec ln -s ~/from/{} ~/to/{} \;


user@osx:~/from$ find . -type f -exec touch ~/to/{} \;
  • Both this and the lndir solution worked. I've "accepted" this because lndir comes with X and may go away or not be present on a system. If you have lndir, though, it's easiest to use. Aug 4, 2010 at 2:48
  • 5 years on this still works. I've not been a serious Unix command line user for over 15 yrs so this brings back great memories (pain :-) Oct 30, 2015 at 19:08

Try lndir. From its man page:

The lndir program makes  a  shadow  copy  todir  of  a  directory  tree
fromdir,  except  that  the shadow is not populated with real files but
instead with symbolic links pointing at the real files in  the  fromdir
directory tree.
  • That's OS X magic!
    – Catherine
    Aug 3, 2010 at 22:15
  • Wow, this would be exactly what I want. It's in /usr/X11 for some reason (the manpage is also listed under X). For some reason, when I run it, like lndir dir1 dir2, I get dir1: No such file or directory. Aug 3, 2010 at 22:26
  • Oh, fixed it. The manpage says The fromdir argument […] is relative to todir (not the current directory). So if you have dir1 and dir2 both in the current directory, you have to type lndir ../dir1 dir2. Of course, typing the full path for dir1 also works. Thanks again. Aug 3, 2010 at 22:31

Another solution that works for me is to use rsync and exclude all files, e.g.

$ rsync -a /path/from/ /path/to/ --include \*/ --exclude \*

The --include \*/ specifies that all directories should be copied, and --exclude \* specifies that all files should be excluded from the copy.

The beauty of this is that the new directory hierarchy has the same attributes, timestamps, permissions, etc as the original.

  • 1
    I agree, having the right attributes is great. Do you know if you can do something about the files, so that they exist (either as empty files or symlinks)? Aug 4, 2010 at 18:57
  • Sorry - I missed that part of the question first time around - it may well be possible with rsync but I'll need to give it some more thought.
    – Paul R
    Aug 5, 2010 at 8:28

Here's one more variation of the rsync method, which will keep folder icons and finder labels:

rsync -Ea /path/from/ /path/to/ --include="*/"  --include="Icon*" --exclude="*"

This doesn't copy file aliases, so you might want to combine it with whitequark's answer above.


This will find the directories inside temp, remove the leading /home/bryan/ from them and create the new directories

  for i in `find /home/bryan/temp -type d| sed 's/\/home\/bryan\///g'`
  do mkdir $i

I suggest typing in the code one line at a time (this way semicolons (not shown) will be placed correctly)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .