SUMMARY: Copying Links

Date: Wed Jan 15 1997 - 08:14:07 CST

     Original Question:
     Hi all,
     Is there an easy way to copy files while preserving their original
     Thanks to everyone in advance...
     tar can also be used to move hierarchies with the command:
     example% cd fromdir; tar cf - .
     | (cd todir; tar xfBp -)
     Tada. :)
     James Neal ( | Microsoft is not the
     answer. UNIX S/N Administrator | Microsoft is the
     question, EE/CS/ME/CE - Portland State University | NO is the answer.
     --=={{ Systems related problems -> }}==--
     There are many ways that you can do this, but one of the simplest is
     just to tar the files like this:
     tar cvf - <source> | (cd <dest_dir>; tar xvf -)
     For example, if you are in /tmp and want to copy the contents of
     directory "blah" to "/tmp/blah1" preserving links, do it like this:
     tar cvf - blah | (cd /tmp/blah1; tar xvf -)
     All links will be preserved. When tar tars up a symbolic link,
     because the "v" (verbose) is specified, you will see "symbolic link".
     If you have any questions, please don't hesitate to ask.
     Jason Keltz
     directory/file top copy for example is data
     tar cf - data | (cd /new/location ; tar xpf -)
     this will copy everything except character files.
     use tar
     do "man tar" to read about it
     tar and cpio will both work. Here's my favorite technique for copying
     /bin/find . -xdev -depth -print|cpio -pduml <destination directory>
     That copies everything from your current directory on downwards to the
     destination you specify. It's how I copy disks.
     Chris Marble - HMC UNIX Systems Manager,
     My opinions are my own and probably don't represent anything anyway.
     two ways that are fairly simple:
     sun% cd <orig dir> ; tar -cvf - . | ( cd <new dir> ; tar -xvfBp - )
     sun% cd <new dir> ; ufsdump 0f - <orig dir> | ufsrestore -rf -
     the ufsdump method also preserves time stamps. in both method, the
     owner of the link will always be root.
     to change the owner you can use several methods including:
     sun% cd <new dir> ; find . -type l -print -exec chown ??? {} \;
     have fun.
     Hello Toby,
     just use rdist.
     Bye Richard.
     Richard Aures
     Unix System Support
     Fon: +49(0)172 6527573 Fax: +49(0)911 9758203 Web:
     You can use this tar - comand
     cd <source>
     tar -cf - . | (cd <target> ; tar -xvfl -)
     The option -l , is the 'copy link' option.
     Trond Isaksen
     tar preserves links
     cd fromdir
     tar cf - * | (cd todir;tar xf -) (Lawson A S)
     By links do you mean "symlinks" and "hard links"? "tar" can do this
     ( cd /old/directory ; tar cf - ) | ( cd /new/directory ; tar xvfp - )
     Stephen Harris <>
     In Bourne shell, the most reliable way to do this is: (cd $SRCDIR;tar
     cf - .)|(cd $DEST;tar xvf -)
     replacing $SRCDIR and $DEST with the full pathnames to the source and
     destination directories respectively.
     Try using tar, for example:
     tar cvf - my_directory | (cd ../my_new_directory; tar xf -)
     It will copy all files under my_directory to ../my_new_directory,
     preserving all links in it
     Fernando Frota Redigolo
     I would use "tar" and "dd"
     __________ ___
     Note: The following commands are for tape device /dev/rst0. If you are
     using a
     second tape device, i.e., 1/4" or 8mm, replace /dev/rst0 with
     ---------- ---
     #---reads writes from: local 1/4" tape to 1/4" remote tape. #
     % dd if=/dev/rst0 bs=126b | rsh <remotesystemname> dd of=/dev/rst0
     #---reads and writes from: remote tape to local tape. #
     % rsh <remotesystemname> dd if=/dev/rst0 bs=126b | dd of=/dev/rst0
     #---reads and writes from: local disk to remote tape. #
     % tar cvfb - 20 <filenames> | rsh <remotesystemname> dd of=/dev/rst0
     #---reads ands writes from: remote tape to local disk. #
     % rsh <remotesystemname> dd if=/dev/rst0 bs=126b | tar -xvpBfb - 126
     #---reads ands writes from: remote tape to local disk. (different
     diredctory) #
     rsh <remotesystemname> dd if=/dev/rst0 bs=126b | (cd <newdir> ; tar
     -xvpBfb - 126)
     #---reads ands writes from: remote disk to local tape. #
     % rsh <remotesystemname> tar cvfb - 126 <filenames> | dd of=/dev/rst0
     #---reads and writes from: local tape to remote disk. #
     % dd if=/dev/rst0 bs=126b | rsh <remotesystemname> | tar -xvpBfb - 126
     #---reads and writes from: remote disk to local disk (same directory).
     % rsh <remotesystemname> tar -cvfbB - 1000 <filenames> | tar -xvfbBp -
     #---reads and writes from: remote disk to local disk (different
     directory). #
     % rsh <remotesystemname> cd <directory> ; tar -cvfbB - 1000
     <filenames> | (cd <newdir> ; tar -xvfbBp - 1000)
     #---reads and writes from: local disk to local disk (different
     directory). #
     cd <directory>
     tar -cvfbB - 1000 <filenames> | (cd <newdir> ; tar -xvfbBp - 1000) #
     #---reads and writes from: local disk to remote disk (different
     directory). #
     cd <directory>
     tar -cvfbB - 1000 <filenames> | rsh <remote-system> "(cd <newdir> ;tar
     -xvpBfb - 1000)"
     See tar(1) and dd(1). Also see bar(1).
     Mark Hargrave
     Mark Hargrave, Sr. Unix Systems Manager Lockheed Martin Manned Space
     PO Box 29304 Mail Stop: 3414
     New Orleans, LA 70189
     Phone: 504-257-1242
     Hi Toby,
     you can use commands like the following:
     find <files-to-copy> -depth -print | cpio -pdm <destination-dir>
     or, if needed remote:
     find <files-to-copy> -depth -print | cpio -o | rsh <desthost> 'cd
     <destination-dir> ; cpio -idm'
     Hope that helps
     Kind Regards - Jens Fischer
     I User : Jens Fischer
     Department : DV-Anwendungsentwicklung Technik
     I N A Company : INA Werk Schaeffler KG
     Address Industriestrasse 1-3
     A D 91074 - Herzogenaurach
     Phone : (+49)9132-823262
     FAX : (+49)9132-824953
     e-mail :
     you can do it either with dump or cpio. With cpio do it as follows
     find . -depth -print | cpio -pdmv newdir
     Notice you must be in the old directory when you run it and newdir
     must be there
     = Mike (Mehran) Salehi (716) 422-2725
     Sure. Use tar (or "bar" or Gnu's tar, "tar") like this:
     (cd /sourcedir;tar cf - file1 file2 dir1 dir2) | (cd /targetdir; tar
     xpf -)
     The "p" flag also preserves permissions. You can add the "v" flag to
     either invocation of tar if you want to watch its progress. And
     obviously, if you're already in the sourcedir or targetdir, you don't
     need one of the "cd" commands.
     Rich Kulawiec

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:42 CDT