[H-CHAT] Re: [H-GEN] Encrypting a tar backup
Jason Parker-Burlingham
jasonp at uq.net.au
Wed Oct 23 12:04:59 EDT 2002
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
Bruce Campbell <bc at humbug.org.au> writes:
> On 23 Oct 2002, Jason Parker-Burlingham wrote:
> > Boy, I'd love to give a talk on the almost complete uselessness of
> > cat(1). Book me for next time I'm in town.
> If your cat(1) is sick, take it to the -vet .
> -n and -s are also useful.
In that case, I'll elaborate for anyone who doesn't already know (all
this can be found by searching for the "useless use of cat" award).
Whenever you see
$ cat file | program
you can usually use
$ program file
instead. It's just as easy for "program" to open, read from and close
the file as it is for it to open, read and close the stdin and stdout
descriptors[1]. The theory goes that the first form is naturally
inefficient, FSVO.
While the efficiency argument is a bit of a furphy, seeing someone
overusing cat usually means you can rely on them to do things the hard
way at other times, too:
$ WRONG=`cat file | grep pattern | wc -l`
$ RIGHT=$(grep -c pattern file)
What's more interesting is working out where cat *is* useful. Bruce
has pointed out one use (although -vet is pretty redundant if you're
using GNU cat, at which point you can just use -A|--show-all
instead). Others include:
# I almost used something like this while testing spam
# assassin; I could not quickly work out how to use bash's
# redirection operators to feed two files[2]---one after the
# other---into formail.
$ program <( cat foo bar baz )
$ cat foo bar baz | program
# numbering lines (cat -n) can be done with grep:
$ grep -n ^ foo
# type a file to the terminal (after making sure it's not too
# long). more(1) or less(1) (with the appropriate options) do
# a better job, however.
$ wc foo; cat foo
It's this last use that I find is the most frequent (going by my (now
extensive) bash history[3]). It makes me wonder how slow and
inefficient cat could be before I'd notice (for really large files,
the speed of the terminal is the limiting factor).
Footnotes:
[1] Yes, they already exist.
[2] Does anyone know how to do this?
[3] I still need to set up process accounting again.
--
||----|---|------------|--|-------|------|-----------|-#---|-|--|------||
| ``It's just a big electric typewriter.'' |
| |
||--|--------|--------------|----|-------------|------|---------|-----|-|
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'. See http://www.humbug.org.au/
More information about the General
mailing list