Copy Directory Structure Only
Does anyone know a command that allows one to copy a directory structure to another location. The structure is very deep and I do not need the files in any of the directories.
|
I don't know if there's a single command to do that... If there is, it might be some form of the find command. Here's a script that will work for you though.
Code:
#!/bin/bash 1. You must be in the top-level directory of the structure you wish to copy when you run the script. 2. You need to change the placeholder text in the script to be the directory you copy the directory structure to. You can use an absolute pathname if you like, but no matter what, it needs to have the trailing slash (which is why it's not listed in red). 3. The script will not actually copy the structure until you remove the # character in front of the mkdir command above. This is a safeguard so you can actually see the commands the script will execute before you "cut it loose" |
find . -type d -exec mkdir /destination/{} \;
example as run by me. find . -type d -exec mkdir /work/work/{} \; does it all, but copies hidden files in top directory only. i can't figure out why. but it's pretty close. cd /work/work; rm .* deletes the hidden files in the top.. maybe i'll figure it out later. |
Re: Copy Directory Structure Only
Quote:
Code:
# cd /new/dir |
Thanks everyone for your help
|
A small change to handle folder names with spaces
# cd /new/dir # (cd /old/dir; find -type d ! -name . -printf "\"%p\"\n") | xargs mkdir "\"%p\"\n" Double quoted path names or else xargs and mkdir will fail |
Edit: :doh: this is a resurrected necro-thread.
@vineel567, please indicate when you are re-opening an old thread so that readers don't confuse it with something being currently discussed. And don't re-open them at all unless you have something important to add to that discussion, such as a correction or updated info. Your current post is fine in that regard, but I would recommend not trying to include hard-coded quotemarks in a command. Instead, use null separators in find and xargs. I'd also recommend using the -p option in mkdir to avoid error messages, and perhaps find's -depth option (although that's not really necessary). Finally, you shouldn't assume that find will operate on the PWD. Always explicitly give the directories it should start searching from. Code:
cd /new/dir Another addition of my own, by the way: How can I recreate a directory hierarchy structure, without the files? http://mywiki.wooledge.org/BashFAQ/010 And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. |
How about this?
Code:
$ find -type d -exec mkdir -p /target-folder/{} \; |
Resurrected is resurrected so... here is another way using rsync:
Code:
rsync -a --include '*/' --exclude '*' /path/to/source user@host: Code:
rsync -a --include '*/' --exclude '*' /path/to/source /path/to/dest |
All these examples are great, but they don't carry over ownership/group or permissions.
|
Quote:
Code:
find . -type d | cpio -pdvm destdir |
All times are GMT -5. The time now is 05:10 AM. |