[mdlug] UNIX tips: Learn 10 good UNIX usage habits
Aaron Kulkis
akulkis3 at hotpop.com
Tue Mar 11 00:46:37 EDT 2008
Clinton V. Weiss wrote:
> Aaron Kulkis wrote:
>> Michael Corral wrote:
>>
>>> 2008-03-10, Monsieur Robert Citek a ecrit:
>>>
>>>> contrast the output of these commands:
>>>>
>>>> $ cat /etc/passwd /etc/group | grep root
>>>> $ grep root /etc/passwd /etc/group
>>>>
>>> grep -h root /etc/passwd /etc/group
>>>
>>> That will give the same output as the cat+pipe version.
>>> So calling cat is unnecessary in this example, since the one grep
>>> command does the same as two commands and a pipe.
>>>
>>> In my experience I've found that calling cat is unnecessary about 95%
>>> of the time.
>>>
>>>
>> The only times cat is necessary...
>>
>> 1: you want the to use one of the flags of cat, such as:
>> cat -n file1 | cmd
>> to prepend each line with a line number.
>>
>> 2: Multiple files to be processed as a single input stream.
>>
>> cat file1 file2 [file3...] | cmd
>
> 3. I want to quickly read the contents of the file.
>
> Clinton =)
That would be true in 1983.
However, since then has come the invention
of both more....and less, too!
more file
or cmd | more
less file
or cmd | less]
(Less allows you to page backwards through piped input).
More information about the mdlug
mailing list