Unix copy and create directory with old school tools

I am using an ancient SunOS.

: uname -a
SunOS ah5719006ub002 5.10 Generic_150400-64 sun4u sparc SUNW,SPARC-Enterprise

I would like to copy files and create a directory at the same time. Is that possible with old SunOS? From what I have read rsync will only create one level of directories. So that is out. All the suggestions I have been able to find depend on newer tools or gnu which I do not have.

Hello,

If you don't have the GNU utilities installed, then I also think you won't have rsync installed, since (unless I'm mis-remembering) I don't think it came out-of-the-box on Solaris 10. You'll certainly be able to get it as a freeware package, if you're able to download and install packages that is.

In terms of a native solution - Sun tar might be your best bet. There are a few caveats and possible pitfalls here, most notably with handling files bigger than 2GB (or 8GB, depending on your patchlevel). But you could give that a go and see how you get on, as that might be the easiest way of doing what you need. If you have all appropriate patches installed, I think tar should be able to handle any size of file on Solaris 10, though it's been a while now since I used it so I can't say for sure.

Overall GNU tar or rsync would probably be your best bet, if you're able to install them. But if you can't, then see if Solaris's native tar can work for you.

2 Likes

@cokedude,
I like @drysdalk's suggestion of using tar to mimic GNU behavior.
Another option would be using cpio with -pduml switches (if memory serves).
You can get specifics from man cpio.
E.g. to copy the whole tree - as a "test harnes":

find  sourcedir  -print | cpio -pduml destdir
2 Likes

@raf
I think you're replying to the wrong thread/topic...

1 Like

Yes, thanks. I saw the How do you do backspace in old school vi? above and answered that. :slight_smile: Sorry for the noise. Let's try again.

This works on Solaris 11. It should work on Solaris 10 as well.

cd dstdir
tar cf - srcdir | tar xf -

But don't run it in the directory that contains srcdir :slight_smile:

A problem with the above is that you will end up with too many directories under dstdir (i.e., all the directories in the path to srcdir). If that's a problem, you need to actually save the tarfile somewhere, e.g.:

cd srcdir
tar cf /tmp/copy.tar .
cd dstdir
tar xf /tmp/copy.tar
rm /tmp/copy.tar

By the way, it's very unlikely that there was ever a version of rsync that only created one level of subdirectories (as long as -r or -a is supplied). If you have it installed, it will probably work:

rsync -av srcdir/ dstdir

I think only tar and cpio can create all needed directories on the fly:

tar cf - srcdir/subdir/afile | ( cd destdir && tar xvf - )
find srcdir/subdir/afile -print | cpio -pduml destdir

tar exactly extracts the stored (relative!) pathnames, so you need to cd where extraction will occur.
tar might have low limits regarding length of file names and file sizes, and cpio even lower.

If there is not a lot of sub dirs you might want to try cp -rp srcdir newdir. The r is recursive the p is preserve dates etc. The r might be R as it's been a while since I worked on Solaris 5. There is a way to do ths with a script using for each and xargs just can't remember exactly how and I don't have access to my old scripts any longer :confused:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.