The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search attributes in one structure using the values from another structure dhanamurthy High Level Programming 3 03-27-2008 03:37 AM
redirection and copying with same directory structure user_prady Shell Programming and Scripting 3 12-10-2007 10:52 PM
Copying with directory structure Cnfsed UNIX for Dummies Questions & Answers 4 11-29-2007 12:51 AM
Need help in Directory Structure murtaza Shell Programming and Scripting 5 03-29-2007 11:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-27-2005
jhansrod jhansrod is offline
Registered User
  
 

Join Date: May 2005
Posts: 80
Copying a Directory Structure to a new structure

Hi all

Is it possible to copy a structure of a directory only.
e.g.
I have a file with the following entries that is a result of a find :-
/dir1/dir2/file.dbf
/dir1/dir2/dir3/file1.dbf
/dir1/file.dbf

I want to copy these to a directory and keep the structure however starting at a new dir :
/newdir/dir1/dir2/file.dbf
/newdir/dir1/dir2/dir3/file1.dbf
/newdir/dir1/file.dbf

when I use the cp -R command, the problem is that because there is a file, it just copies the file and not the structure.

Regards
J
  #2 (permalink)  
Old 07-27-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Your post is similiar to this

Use tar


vino
  #3 (permalink)  
Old 07-27-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Found from http://www.tldp.org/LDP/abs/html/spe...rs.html#BGLOOP

Quoting word-to-word from the above url.

Code:
redirection from/to stdin or stdout [dash].

(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)
# Move entire file tree from one directory to another
# [courtesy Alan Cox <a.cox@swansea.ac.uk>, with a minor change]

# 1) cd /source/directory    Source directory, where the files to be moved are.
# 2) &&                     "And-list": if the 'cd' operation successful, then execute the next command.
# 3) tar cf - .              The 'c' option 'tar' archiving command creates a new archive,
#                            the 'f' (file) option, followed by '-' designates the target file as stdout,
#                            and do it in current directory tree ('.').
# 4) |                       Piped to...
# 5) ( ... )                 a subshell
# 6) cd /dest/directory      Change to the destination directory.
# 7) &&                     "And-list", as above
# 8) tar xpvf -              Unarchive ('x'), preserve ownership and file permissions ('p'),
#                            and send verbose messages to stdout ('v'),
#                            reading data from stdin ('f' followed by '-').
#
#                            Note that 'x' is a command, and 'p', 'v', 'f' are options.
# Whew!



# More elegant than, but equivalent to:
#   cd source/directory
#   tar cf - . | (cd ../dest/directory; tar xpvf -)
#
# cp -a /source/directory /dest/directory     also has same effect.
Vino
  #4 (permalink)  
Old 07-27-2005
jhansrod jhansrod is offline
Registered User
  
 

Join Date: May 2005
Posts: 80
MY apologies, but what I forgot to mention is that I dont want all the files in the tree.
e.g.
/dir1/dir2/file1.dbf
/dir1/dir2/dir3/file2.dbf
/dir1/file3.dbf
/dir1/dir2/anotherfile.txt
/dir1/dir2a/file2a.dbf
to

/dir1/dir2/file1.dbf
/dir1/dir2/dir3/file2.dbf
/dir1/file3.dbf
/dir1/dir2a/file2a.dbf

THanx

J
  #5 (permalink)  
Old 07-27-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
I assume that your find is something like this

find /dir1 -name '*.dbf'

In that case, use

tar cvf - `find /dir1 -name '*.dbf'` > dir1.tar

Whatever your find is, put it betwen the backticks ` `.

Go to /newdir and untar the dir1.tar

vino
  #6 (permalink)  
Old 07-27-2005
jhansrod jhansrod is offline
Registered User
  
 

Join Date: May 2005
Posts: 80
Hi Vino

Thanks for the responses. What if I have my source listed in a file and want to use the for loop to do the copy. As mentioned, the copy works, but unfortunately does not copy the structure and only the file in the target dir.

Thanks

J
  #7 (permalink)  
Old 07-27-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
tar cvf - `find /dir1 -name '*.dbf'` > dir1.tar

So you are saying this doesnt work at all, i.e. it doesnt duplicate the directory structure ??

vino
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0