foxfirefey: A fox colored like flame over an ornately framed globe (Default)
foxfirefey ([personal profile] foxfirefey) wrote in [community profile] command_liners2011-11-23 12:38 pm

Bad command line habits and good ones to replace them

UNIX tips: Learn 10 good UNIX usage habits, as follows:

  • Make directory trees in a single swipe.
  • Change the path; do not move the archive.
  • Combine your commands with control operators.
  • Quote variables with caution.
  • Use escape sequences to manage long input.
  • Group your commands together in a list.
  • Use xargs outside of find .
  • Know when grep should do the counting -- and when it should step aside.
  • Match certain fields in output, not just lines.
  • Stop piping cats.


I learned a couple of things from this one!
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2011-11-24 06:50 am (UTC)(link)
Ooooh interesting, thanks! *bookmarks to read later*
floatboth: (Default)

[personal profile] floatboth 2011-11-24 10:27 am (UTC)(link)
Also, $(command) instead of `command`.
And ack is better than grep.
Get moreutils and pipetk.

Thank you for this! :-)

[personal profile] babysprite 2011-11-25 07:19 pm (UTC)(link)

It's always good to pick tips and tricks, wherever they can be found.

The point with me is that I can always learn more to be a better UNIX user.

vaxhacker: (Default)

[personal profile] vaxhacker 2011-11-26 04:16 am (UTC)(link)
I never understood why so many people got in the habit of doing "cat file | ...". These are good for people to know. :)

[personal profile] tara_hanoi 2011-11-28 10:15 am (UTC)(link)
Yeah, it always gets me when I see people do "cat $file | more" in work.

That said, while I'll always do "$cmd $file | ..." there is one thing to be said for the "cat $file | ..." style: when you're working on your super-huge command-line and you're still fine-tuning all the commands you're piping through, it's easier to leave the "cat $file" bit untouched, and then chop and change your filter commands ("Hmmm, maybe I want to swap the first grep and awk"), and tidy it up when you're done. If you're just testing how you're going to order your commands, then an extra fork/exec and pipe isn't going to kill you. :)
tcpip: (Rats)

[personal profile] tcpip 2012-02-09 11:28 pm (UTC)(link)
Listing #4 is a very good habit which I should cultivate.

And nobody should pipe a cat. Cats are perfectly capable of getting into pipes themselves.