I have a folder with about 20K files. The files are named according to the pattern
xy_12345_1234.abc. I wanted to compress the first 10K of them using this command:
ls | sort -n -k1.4,1.9 | head -n10000 | xargs tar -czf xy_0_10000.tar.gz
however the resulting file had only about 2K files inside.
ls | sort -n -k1.4,1.9 | head -n10000 | wc -l however returns 10000, as expected.
It seems to me that I am misunderstanding something basic here...
I am using zsh 5.0.2 on Linux Mint 17.1, GNU tar 1.27.1
forking as suggested by @Archemar sounds very plausible, with the latest fork overwriting the resulting file - the file contains the 'tail' of the files - 7773 to 9999.
Your environment variables take up 3973 bytes
POSIX upper limit on argument length (this system): 2091131
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2087158
Size of command buffer we are actually using: 131072
-u did not work in my case. The error message was
tar: Cannot update compressed archives
-u is invalid and fails with
tar: You may not specify more than one '-Acdtrux', '--delete' or '--test-label' option
-a seems to be invalid as well and fails with the same
tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options though I dont recognize the issue
Acdtrux seem disjunct to me.
-T looks like a good way, I have also found an example here.
However when I try
ls | sort -n -k1.4,1.9 | head -n10000 | tar -czf xy_0_10000.tar.gz -T - i get
tar: option requires an argument -- 'T'
well, perhaps the filenames dont reach tar? But it looks like they, do because when I execute
ls | sort -n -k1.4,1.9 | head -n10000 | tar --null -czf xy_0_10000.tar.gz -T - i get
tar: xy_0_.ab\nxy_1_...<the rest of filenames separated by literal \n>...998.ab
Cannot stat: File name too long
So why is tar not seeing the filenames?