The Joy of UNIX

Posted Tuesday 23rd September, 2008

One of the best things about developing from a Mac is the fact that it is a UNIX-based operating system. This means that my development environment is a far closer match to my production hosting environment (Linux) than it was when I was developing under Windows.

The net result of this shift in paradigm is a rapidly expanding knowledge of the command-set and OS structure. The exposure to UNIX has done me the world of good; particularly in regard to web development and server management. Sadly, the relative shelter I was accustomed to at Rentokil Initial, thanks to the inclusion of immensely talented and helpful server admins within our team, had hindered my development as a web developer, and provoked ridicule at the hands of my fellow Y! EU developers (in the nicest possible way, of course).

With all that in mind, here’s a bunch of stuff I’ve learnt that might be a useful reference resource…

Books

The first book I’d recommend reading for a good grounding in UNIX is ”The UNIX Programming Environment”, by Brian W. Kernighan and Rob Pike. Although this is book is over 20 years old, it’s still highly relevant; Kernighan and Pike both worked at Bell Labs during the development of UNIX and contributed greatly to the OS and its school of thought. The book covers a huge expanse of subjects, from the basics through to full program development.

The second book, as is so often the case, is published by O’Reilly. ”UNIX in a Nutshell”, by Arnold Robbins, is a great, up-to-date examination of the operating system, including a vast array of information perfect for beginners and experienced users alike.

Both of these books should provide enough knowledge for you to feel safe getting down and dirty with UNIX; so let’s dive in with a look at some useful keyboard and command line shortcuts:

Keyboard and Command Line Shortcuts

The following are common keyboard and command line shortcuts for use in UNIX-based systems. Please note that all UNIX variants differ and some of these shortcuts may not be available to you, or may require different syntax or keystrokes.

Keyboard Shortcuts

To begin with, here’s a list of useful keyboard shortcuts:

Most of those are self-explanatory, but you’ll wonder how you lived without them soon enough.

Command Line Shortcuts

Next, let’s take a look at some useful command line shortcuts, starting with directory navigation:

Here’s a quick demonstration to hopefully make their use a little clearer (the names have been changed to protect the innocent). Note, this example uses several UNIX commands; cd = change directory, pwd = print working directory, ls = list contents of directory, and cp = copy files:

$ pwd
/Users/timbo
$ cd /var/www/nefarious/
$ pwd
/var/www/nefarious
$ cd ..
$ pwd
/var/www
$ ls
a-website   another-website   nefarious
$ cd /var/www2
$ pwd
/var/www2
$ ls
$ cp /var/www/* ./
$ ls
a-website   another-website   nefarious
$ cd ~
$ pwd
/Users/timbo

Now that we can effectively navigate the directory structure, let’s have a look at the incredibly useful history utility and its command line shortcuts:

I won’t go into detail on each one of those, but here’s an example of the last one — arguably the most useful — in action:

$ pwd
/Users/timbo
$ ls projects/django/
cms    coltrane    davis
$ cd !$
cd projects/django/
$ pwd
/Users/timbo/projects/django

Summary

This is just a quick reference to some useful shortcuts; I could have delved deeper into setting up aliases in your profiles and making your prompt look pretty, but I thought I’d save that for a possible follow up post.

I hope somebody out there finds this useful; and feel free to add your own tips and tricks in the comments.

Included in: Development, Linux, Mac OS X, Reference, Server, UNIX, Web

Categories:

  1. Accessibility
  2. Ajax
  3. Apache
  4. API
  5. Architecture
  6. Books
  7. Browsers
  8. CMS
  9. CouchDB
  10. CSS
  11. Design
  12. Development
  13. Django
  14. Email
  15. Events
  16. Gaming
  17. Grammar
  18. Hardware
  19. HTML
  20. HTTP
  21. Humour
  22. Idea
  23. Information Architecture
  24. JavaScript
  25. jQuery
  26. Life
  27. Linux
  28. Literature
  29. Mac OS X
  30. Meme
  31. Microformats
  32. Monday
  33. MySQL
  34. Networking
  35. News
  36. Personal
  37. Photoshop
  38. PHP
  39. Python
  40. Reference
  41. REST
  42. Science
  43. SEO
  44. Server
  45. Site
  46. Sitepimp
  47. Social
  48. Spelling
  49. Syndication
  50. Testing
  51. The Future
  52. Thoughts
  53. Tools
  54. Tutorials
  55. Typography
  56. UI
  57. UNIX
  58. Virtualisation
  59. Web
  60. Web Standards
  61. Widgets
  62. Wii
  63. Writing
  64. Xbox
  65. XHTML