[Wylug-help] I broke my man files

Aaron Crane wylug at aaroncrane.co.uk
Thu Dec 8 00:42:18 GMT 2005


RichardA writes:
> Aaron Crane <wylug at aaroncrane.co.uk> wrote:
> >   for f in /usr/*/man/man*/*.gz; do
> >     if file -b "$f" | grep -wqv gzip; then
> >       mv -i "$f" "${f%.gz}" &&
> >       gzip -9 "${f%.gz}"
> >     fi
> >   done
> 
> I think the script says: if a file isn't a gzip, rename it to .gz and
> gzip it?

No -- if it isn't a gzip, rename away the ".gz" bit, and then gzip it.
"${f%.gz}" means "the value of $f, but without any trailing .gz".

> But it's only acting on files already named .gz?

The "-v" option to grep means "true only if no lines match" (rather than
the usual "true if at least one line matches").  So the "grep -wqv gzip"
test is true only if the input doesn't contain the whole word "gzip".

> And doesn't 'mv-i' mean interactive?

"Interactively ask before overwriting a destination file that already
exists."

I actually wanted to say "never overwrite an already-existing
destination file", but there's no option for that.  You can say "mv
--reply=no", but that does something else: it means "don't overwrite if
the destination already exists and there would otherwise be a prompt to
ask if you really meant to delete".  Personally, I think that's never
useful behaviour, and that the documentation (at least in coreutils
5.2.1, which is the version in Debian Sarge) fails to describe
adequately what "--reply=no" does mean.  Hmm, apparently I'm not alone:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=274705
  http://lists.gnu.org/archive/html/bug-coreutils/2005-06/msg00160.html

-- 
Aaron Crane



More information about the Wylug-help mailing list