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