Different syntax for 'tar' in linux and solaris.

Different syntax for 'tar' in linux and solaris.

Post by Mothr » Thu, 14 Oct 2004 19:59:10



 > Linux
 > tar cvf home.tar -N yesterday /home
 >
 > In solaris
 > I want same function like "tar cvf home.tar -N yesterday /home " in
solaris.
 > How to use "tar" ?

Have you tried:

find . -type f -mtime 1 | xargs /usr/bin/tar cvf home.tar

Works for me.

 
 
 

Different syntax for 'tar' in linux and solaris.

Post by Mothr » Fri, 15 Oct 2004 01:07:44




>  > Linux
>  > tar cvf home.tar -N yesterday /home

>  > In solaris
>  > I want same function like "tar cvf home.tar -N yesterday /home " in
> solaris.
>  > How to use "tar" ?

> Have you tried:

> find . -type f -mtime 1 | xargs /usr/bin/tar cvf home.tar

> Works for me.

There seems to be some gnashing of egos in another thread about this,
but I've yet to hear a convincing argument against the solution.

Amazingly though, my honest attempt at helping a fellow Unix user has
prompted the following backlash:

"You obviously never tryed [sic] this as it definitely does not work."

So I ran the command again several times, then posted the screen output
and got the following response:

"Do you really beieve [sic] that you may prove things just by running a
test that succeeds by accident?"

Another more sane response was:

"Beside the fact that it fails for filenames with SPC, TAB, NL,
single, double quotes or backslashes, it will also fail if the
list of files is long enough so that several instances of tar
are run."

OK, but what are such files doing on a Solaris operating system? I would
regard spaces in filenames as a minor sin, but TAB and NL for *'s
sake?  Even Windows Sys Admins would balk at that!

The second point is dubious as it all depends on your environment.
xargs can fall over if you give it thousands and thousands of files
under certain shells; yes, OK I admit it - my solution is slightly flaky
when placed under extreme scrutiny.

However I just ran "print {1..200000} | xargs" (under zsh) and after
some time, it came back with the the numbers all printed without line
breaks, just as it would if you supplied all args to the print command
in one single line.  If xargs was spawning a separate print command for
each arg, the output would have a "\n" written at the end, thereby
printing one number per line.

And... ahh shit, I can't be bothered.  I'm catching a plane to Cancun in
12 hours' time.  Someone please take my corner and argue it amongst
yourselves...

 
 
 

Different syntax for 'tar' in linux and solaris.

Post by j.. » Fri, 15 Oct 2004 01:31:13





> >  > Linux
> >  > tar cvf home.tar -N yesterday /home

> >  > In solaris
> >  > I want same function like "tar cvf home.tar -N yesterday /home "
> > in solaris.
> >  > How to use "tar" ?
> > Have you tried:
> > find . -type f -mtime 1 | xargs /usr/bin/tar cvf home.tar
> > Works for me.

> There seems to be some gnashing of egos in another thread about this,
> but I've yet to hear a convincing argument against the solution.

> Amazingly though, my honest attempt at helping a fellow Unix user has
> prompted the following backlash:

> "You obviously never tryed [sic] this as it definitely does not work."

> So I ran the command again several times, then posted the screen
> output and got the following response:

> "Do you really beieve [sic] that you may prove things just by
> running a test that succeeds by accident?"

It wasn't by accident really, it was simply that you didn't provide
xargs with a list of files that was long enough for it to have to
invoke tar more than once. The point of xargs, after all, is to invoke
the target command as often as needed. If you do that using the 'c'
option to tar, you will overwrite the previous tar file, using 'r'
instead, as was suggested, will append files to the existing tar file.

Quote:> The second point is dubious as it all depends on your
> environment. xargs can fall over if you give it thousands and
> thousands of files under certain shells; yes, OK I admit it - my
> solution is slightly flaky when placed under extreme scrutiny.

I don't know why you think this, because xargs reads the file names
from stdin, not the command line.

Quote:> And... ahh shit, I can't be bothered.  I'm catching a plane to
> Cancun in 12 hours' time.  Someone please take my corner and argue
> it amongst yourselves...

Have a nice vacation, it sounds like you need one :-)

Joe (ps, be ready for some really crazy van drivers)
--
Always drink upstream from the herd.
  - Will Rogers

 
 
 

Different syntax for 'tar' in linux and solaris.

Post by Stephane CHAZELA » Fri, 15 Oct 2004 16:45:19


2004-10-13, 16:07(+00), Mothra:
[...]

Quote:> "Beside the fact that it fails for filenames with SPC, TAB, NL,
> single, double quotes or backslashes, it will also fail if the
> list of files is long enough so that several instances of tar
> are run."

> OK, but what are such files doing on a Solaris operating system? I would
> regard spaces in filenames as a minor sin, but TAB and NL for *'s
> sake?  Even Windows Sys Admins would balk at that!

They are allowed in filenames. Even if it's not reasonable to
create such files, one dumb or * user may want to create one
especially if he/she has an interest in breaking you script.

Quote:> The second point is dubious as it all depends on your environment.
> xargs can fall over if you give it thousands and thousands of files
> under certain shells; yes, OK I admit it - my solution is slightly flaky
> when placed under extreme scrutiny.

> However I just ran "print {1..200000} | xargs" (under zsh) and after
> some time, it came back with the the numbers all printed without line
> breaks, just as it would if you supplied all args to the print command
> in one single line.  If xargs was spawning a separate print command for
> each arg, the output would have a "\n" written at the end, thereby
> printing one number per line.

[...]

Then your xargs behaves differently as the one I have on a
Solaris 8 box.

With xargs on Solaris 8 here, you can't have more than 255
arguments.

$ print {1..200000} | xargs | wc -l
     788

(788 instances of echo).

With a 40 bytes long average filename, that would be the other
limit that would be broken first, the command line length, so
your solution would start breaking around 50 files to archive.

--
Stephane