Operating System - Linux
1752806 Members
6143 Online
108789 Solutions
New Discussion юеВ

tar command seems to only bundle-up the last file in the list when used with find.

 
SOLVED
Go to solution
Danny Fang
Frequent Advisor

tar command seems to only bundle-up the last file in the list when used with find.

Hi,
I'm attempting to bundle-up approximately 70+ files into a tar bundle by using the find command.

Although the files are seen to be bundled up in the tar-bundle, in fact, they aren't.

The tar -tvf .tar shows that there is only file in the bundle and apparently it's the last file in the directory to be bundled.

bash-2.05$ find . -depth -type f -size 0 -exec tar -cvf zero-sized.tar {} \;
a ./002/008/aOFS_BSM_P02000000 0K
a ./002/008/aOFS_OMU_P02000000 0K
a ./002/008/aOFS_TMU_P02000000 0K
a ./002/008/aOFS_CC_P02000000 0K
a ./002/008/aOFS_BSC3GCEM_P02000000 0K
a ./002/008/aOFS_TCU3GCEM_P02000000 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000000 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000000 0K
a ./002/008/aOFS_BSM_P02000100 0K
a ./002/008/aOFS_OMU_P02000100 0K
a ./002/008/aOFS_TMU_P02000100 0K
a ./002/008/aOFS_CC_P02000100 0K
a ./002/008/aOFS_BSC3GCEM_P02000000 0K
a ./002/008/aOFS_TCU3GCEM_P02000000 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000000 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000000 0K
a ./002/008/aOFS_BSM_P02000100 0K
a ./002/008/aOFS_OMU_P02000100 0K
a ./002/008/aOFS_TMU_P02000100 0K
a ./002/008/aOFS_CC_P02000100 0K
a ./002/008/aOFS_BSC3GCEM_P02000100 0K
a ./002/008/aOFS_TCU3GCEM_P02000100 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000100 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000100 0K
a ./002/008/aOFS_BSM_P02000200 0K
a ./002/008/aOFS_OMU_P02000200 0K
a ./002/008/aOFS_TMU_P02000200 0K
a ./002/008/aOFS_CC_P02000200 0K
a ./002/008/aOFS_BSC3GCEM_P02000200 0K
a ./002/008/aOFS_TCU3GCEM_P02000200 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000200 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000200 0K
a ./002/008/aOFS_BSM_P02000300 0K
a ./002/008/aOFS_OMU_P02000300 0K
a ./002/008/aOFS_TMU_P02000300 0K
a ./002/008/aOFS_CC_P02000300 0K
a ./002/008/aOFS_BSC3GCEM_P02000300 0K
a ./002/008/aOFS_TCU3GCEM_P02000300 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000300 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000300 0K
a ./002/008/aOFS_BSM_P02000400 0K
a ./002/008/aOFS_OMU_P02000400 0K
a ./002/008/aOFS_TMU_P02000400 0K
a ./002/008/aOFS_CC_P02000400 0K
a ./002/008/aOFS_BSC3GCEM_P02000400 0K
a ./002/008/aOFS_TCU3GCEM_P02000400 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000400 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000400 0K
a ./002/008/aOFS_BSM_P02000500 0K
a ./002/008/aOFS_OMU_P02000500 0K
a ./002/008/aOFS_TMU_P02000500 0K
a ./002/008/aOFS_CC_P02000500 0K
a ./002/008/aOFS_BSC3GCEM_P02000500 0K
a ./002/008/aOFS_TCU3GCEM_P02000500 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000500 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000500 0K
a ./002/008/aOFS_BSM_P02000600 0K
a ./002/008/aOFS_OMU_P02000600 0K
a ./002/008/aOFS_TMU_P02000600 0K
a ./002/008/aOFS_CC_P02000600 0K
a ./002/008/aOFS_BSC3GCEM_P02000600 0K
a ./002/008/aOFS_TCU3GCEM_P02000600 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000600 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000600 0K
a ./002/008/aOFS_BSM_P02000700 0K
a ./002/008/aOFS_OMU_P02000700 0K
a ./002/008/aOFS_TMU_P02000700 0K
a ./002/008/aOFS_CC_P02000700 0K
a ./002/008/aOFS_BSC3GCEM_P02000700 0K
a ./002/008/aOFS_TCU3GCEM_P02000700 0K
a ./002/008/aOFS_BSC3GPCMPORT_P02000700 0K
a ./002/008/aOFS_TCU3GPCMPORT_P02000700 0K
a ./002/008/aOFS_BSM_P02000800 0K
bash-2.05$ tar -tvf zero-sized.tar
tar: blocksize = 3
-rw-r----- 5041/111 0 Oct 6 10:05 2008 ./zero-sized/aOFS_TCU3GPCMPORT_P02000700
bash-2.05$ df -k .
Filesystem kbytes used avail capacity Mounted on
klstor01:/datavol/prodkl
47185920 43803530 3239390 94% /nfs/kl/prodkl
bash-2.05$

Note that the disk usage has not even reached 100% yet.

Could anyone help out with this issue?

Thanks
Danny.
3 REPLIES 3
Ivan Ferreira
Honored Contributor
Solution

Re: tar command seems to only bundle-up the last file in the list when used with find.

You are replacing your tar file at each tar command, so, having only the last file on it is normal.

You should use the concatenate (-A) option instead of the create (-c) option.

You may change your command also as below:

tar cvf zero-sized.tar $(find . -depth -type f -size 0 )
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Hemmetter
Esteemed Contributor

Re: tar command seems to only bundle-up the last file in the list when used with find.

Hi Danny,

You may also replace the \; to \+ in your find-command. This prevents also executing tar for each file by cumulating occurances of {}.

Thus:

$ find . -depth -type f -size 0 -exec tar -cvf zero-sized.tar {} \+


see find(1) about parameter -exec




rgds
HGH
Steven Schweda
Honored Contributor

Re: tar command seems to only bundle-up the last file in the list when used with find.

If we assume that you're in the right forum
(Linux), then your "tar" should be GNU "tar", and GNU "tar" offers some useful options,
like "--files-from=- or -T -", which causes
it to read from standard input a list of
files to process. You could simply pipe the
output from your "find" command into a single
"tar" command using this technique.

http://www.gnu.org/software/tar/manual/tar.html#SEC101


> see find(1) about parameter -exec

"man find" could be informative, too, if
it's still not clear why your original
command failed.