LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem in copying directory structure (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-copying-directory-structure-652217/)

agogoaye 06-28-2008 05:32 AM

Problem in copying directory structure
 
Hi everyone.

I use

(cd /old/directory; find -type d ! -name .) | xargs mkdir

for copying directory structure into another location. It works.

Then I found a problem. If I have folder named "linux newbie", or another folder that use space character. It will be splitted into 2 folder, "linux" and "newbie".

Does anyone know how to repair my command? Please help me to modify my command.

Thanks

alan_ri 06-28-2008 05:42 AM

Hi and welcome!
Why don't you just rename your folder to linux_newbie,then your command will work.

agogoaye 06-28-2008 05:50 AM

thanks for your advisement :)

but i need to copying directory structure, without renaming any directory. is there another way? :confused:

solarkash 06-28-2008 03:53 PM

cd $OLD_DIR && find . -type d ! -name . -exec mkdir $NEW_DIR/{} \;

colucix 06-28-2008 04:46 PM

To manage spaces inside file or directory names, you have to use the -print0 action of find and the corresponding -0 option of xargs. The former prints the path names terminated by a null character, the latter interprets arguments separated by a null character instead of the common field separators as blank space, tab and newline. You should end up with something like:
Code:

find . -type d ! -name . -print0 | xargs -0 mkdir
Anyway, I find more feasible to copy a directory structure using rsync, like this:
Code:

rsync -av --include '*/' --exclude '*' /old/directory/* /new/directory

dina3e 06-28-2008 10:20 PM

Quote:

Originally Posted by colucix (Post 3197970)
To manage spaces inside file or directory names, you have to use the -print0 action of find and the corresponding -0 option of xargs. The former prints the path names terminated by a null character, the latter interprets arguments separated by a null character instead of the common field separators as blank space, tab and newline. You should end up with something like:
Code:

find . -type d ! -name . -print0 | xargs -0 mkdir
Anyway, I find more feasible to copy a directory structure using rsync, like this:
Code:

rsync -av --include '*/' --exclude '*' /old/directory/* /new/directory



can is it possible to only copy the tree structure of the directory not the file content inside the directory to other directory.(Only tree structure of the directory).

colucix 06-29-2008 03:24 AM

Quote:

Originally Posted by dina3e (Post 3198150)
can is it possible to only copy the tree structure of the directory not the file content inside the directory to other directory.(Only tree structure of the directory).

Sorry, but is this a question or a comment? The topic of this thread is all about copying a directory structure and the rsync command I suggested does exactly what you're looking for. It includes directories '*/' and excludes files '*'.

dina3e 06-30-2008 09:26 PM

Quote:

Originally Posted by colucix (Post 3198293)
Sorry, but is this a question or a comment? The topic of this thread is all about copying a directory structure and the rsync command I suggested does exactly what you're looking for. It includes directories '*/' and excludes files '*'.

My question, is it possible that the structure of the directory is constant i mean all the files are at the same position but the content of the file is to be NULL. so that we keep the top to bottam structure of the directory not the file content.

colucix 07-01-2008 12:32 AM

Quote:

Originally Posted by dina3e (Post 3199833)
My question, is it possible that the structure of the directory is constant i mean all the files are at the same position but the content of the file is to be NULL.

Not in one command. If you copy or sync a file, it will be as is. You have to do some scripting to accomplish that: for example copy the directory structure with the rsync command, then find the files inside the original structure and touch them (that is create empty) inside the new one.

agogoaye 07-02-2008 04:44 AM

thanks everybody :)


All times are GMT -5. The time now is 11:28 AM.