LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-28-2008, 06:32 AM   #1
agogoaye
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 0
Unhappy 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
 
Old 06-28-2008, 06:42 AM   #2
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Hi and welcome!
Why don't you just rename your folder to linux_newbie,then your command will work.
 
Old 06-28-2008, 06:50 AM   #3
agogoaye
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Original Poster
Rep: Reputation: 0
thanks for your advisement

but i need to copying directory structure, without renaming any directory. is there another way?
 
Old 06-28-2008, 04:53 PM   #4
solarkash
LQ Newbie
 
Registered: Jun 2008
Posts: 11

Rep: Reputation: 1
cd $OLD_DIR && find . -type d ! -name . -exec mkdir $NEW_DIR/{} \;
 
Old 06-28-2008, 05:46 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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
 
Old 06-28-2008, 11:20 PM   #6
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
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).
 
Old 06-29-2008, 04:24 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by dina3e View Post
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 '*'.
 
Old 06-30-2008, 10:26 PM   #8
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
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.
 
Old 07-01-2008, 01:32 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by dina3e View Post
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.
 
Old 07-02-2008, 05:44 AM   #10
agogoaye
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Original Poster
Rep: Reputation: 0
thanks everybody
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying a single file into each directory of a directory tree mlapl1 Linux - Newbie 2 06-27-2007 11:18 PM
Directory Structure fedix Linux - Newbie 3 10-14-2005 03:48 PM
copying directory structure in FTP malaka56 Linux - Software 2 05-14-2005 08:04 PM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 11:55 PM
"WARNING: Circular directory structure" error when deleting directory pistonbrew Linux - Software 5 02-03-2005 07:05 AM


All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration