![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
|||||
|
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.
|
|
||||
|
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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|