A basic-but-common grep
usage error involves pipe’ing the output of cat
to grep
to search the contents of a single file. This is absolutely unnecessary and a waste of time, because tools such as grep
take file names as arguments. You simply do not need to use cat
in this situation at all, as in the following example:
[root@un1xf00 root]# time cat passwd | grep root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
real 0m0.021s
user 0m0.000s
sys 0m0.030s
[root@un1xf00 root]# time grep root passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
real 0m0.002s
user 0m0.000s
sys 0m0.000s
[root@un1xf00 root]#
Checkout the time taken for both the commands. Dont pipe cat!.