Disclaimer: Yes, finding files in a script with ls
is bad, but find
can't sort by modification date.
Using ls
and xargs
with echo
everything is fine:
$ ls -t1 ssl-access*.gz | xargs -n 1 echo
ssl-access.log.2.gz
ssl-access.log.3.gz
ssl-access.log.4.gz
[...]
Changing echo
to zcat
:
$ ls -t1 ssl-access*.gz | xargs -n 1 zcat
gzip: ssl-access.log.2.gz.gz: No such file or directory
gzip: ssl-access.log.3.gz.gz: No such file or directory
gzip: ssl-access.log.4.gz.gz: No such file or directory
[...]
Duplicate file suffixes?! What is going on here?
UPDATE:
OS is Debian 5.
zcat
is a shell script at /bin/zcat
:
#!/bin/sh
PATH=${GZIP_BINDIR-'/bin'}:$PATH
exec gzip -cd "$@"
zcat
executable (probably a shell script) and see if it is auto-appending a.gz
extension. – jw013 Oct 21 '11 at 20:51-printf %t
(gnu-only) or-exec stat -c '%X' {}\;
then pipe it tosort
. – Shawn J. Goff Oct 21 '11 at 21:10zcat
a file that is not compressed? – Shawn J. Goff Oct 21 '11 at 23:14gzip: test.txt: not in gzip format
with return code 1. – Christoph Wurm Oct 21 '11 at 23:19xargs
is running the command for a batch of files at once, and you're not using this capability, so don't even consider using it. About the strange behavior you observe: what doestype zcat
show? What is the *full* output fromls -t1 ssl-access*.gz
? – Gilles 'SO- stop being evil' Oct 22 '11 at 02:11gunzip -c
. On systems that have a compress package installed, in there is already a zcat program that reads.Z
files, so the gzip edition ofzcat
is installed asgzcat
(which you noted below you don't have. can you modify your script to usels -t1 ssl-access*.gz | xargs -n 1 gunzip -c
? – Tim Kennedy Oct 22 '11 at 04:52ls -alF ssl-access*.gz
? Maybe they are symlinks pointing to missing files. – janmoesen Oct 22 '11 at 07:12--verbose
to thexargs
andzcat
invocations. It should at least tell you which program is adding the extra.gz
. – James Sneeringer Oct 23 '11 at 00:53ls
command withls -C --color=always --indicator-style=slash --group-directories-first
. The--color=always
seems to screw everything up when the output ofls
is reused. I use this option to view colored output even when piping intoless
(got it from this answer) What is the correct way of handling this question? – Christoph Wurm Oct 23 '11 at 08:07