Good command line usage habits and tips

Aug 24, 2010 - 4 Comments

If you use the command line frequently, chances are you may have some bad command line habits. IBM’s DeveloperWorks site has posted 10 good UNIX usage habit tips, some of them are just pretty handy tricks in general and if you’re new to the Mac OS X Terminal, you’ll probably learn something since practically all of them work within the Mac OS X command line. Here’s one of my personal favorites since it hit home with my command line activities:

* Change the path to unpack something into rather than moving the archive file itself, in this example by using the -C flag with the tar command:

tar xvf -C path/to/unpack newarc.tar.gz

I’m certainly guilty of moving archives around, but that’s partially because I like to keep all of them in a central location. But if you’re going to just delete the archive anyway, there’s no point in moving the archive file around just to unpack it. Save yourself the keystrokes.

Here’s the full list of tips in the IBM DeveloperWorks article:

* 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

Check them out: IBM DeveloperWorks: Learn 10 good UNIX usage habits

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line

4 Comments

» Comments RSS Feed

  1. Woodgie says:

    Absolutely excellent, thank you!

  2. motoko says:

    tar xvf -C path/to/unpack newarc.tar.gz

    but the newarc is gzipped…tar can uncompress a gzipped file?

    • motoko says:

      on 10.5.8 works:

      tar xvf path/to/gzippedtarfile -C path/to/unpack

      p.s.=I didn’t know that the z option can be omitted

  3. devilspride says:

    tar -zxvf path/to/gzippedtarfile -C path/to/unpack

    z will use gzip to uncompress it

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates