Unix Tip #4350- February 7, 2024


SEARCH : Home : Help : Today's Tip

THE BAD AND THE GOOD


I cringe anytime I see someone code inefficiently. Here are
three of the most common mistakes, followed by a better way to
do the same thing.

Bad: cat somefile | grep something
Better: grep something somefile
Why: You're running one program (grep) instead of two (cat
and grep).

Bad: ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why: You’re running two commands (grep) instead of three (ps
and two greps).

Bad: cat /dev/null > somefile
Better: > somefile
Why: You're running a command (cat) with I/O redirection,
instead of just redirection.

Although the bad way will have the same result, the good way is
far faster. This may seem trivial, but the benefits will really
show when dealing with large files or loops.


This tip generously supported by: sec@nbnet.nb.ca

NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted by various unix admins around the globe. UGU suggest you read and test each tip in a non-volitile environment before placing into production.


LAST 5 TIPS
4349 - SUSPEND A VI SESSION FOR SHELL
4348 - BC AND NOT BEFORE AD
4347 - LISTING FILES BY SIZE
4346 - WHERE AM I ALWAYS
4345 - WHO SENT ME MAIL


I want to SUBSCRIBE and get a UGU Tip everyday.
I want to UNSUBSCRIBE and NOT get a UGU Tip everyday.

If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
Email Address:

Yes, email me a Hot Unix Tip everday.

Enter Hot Unix Tip (optional):

Yes, I will support this tip

Captcha (not case sensitive):


Please enter the above letters:


HOME | Flavors | Admin | Network | Security | S/W | Help | Events | Vendors | Careers | Internet
About | Add Link | Feedback | Search

Copyright © 1994-2005 Unix Guru Universe