Learning the Unix Shell (bash)


Last month I mentioned a quest to learn the Unix shell .. specifically » bash (the Bourne Again SHell). Almost done. Currently ~80% complete .. enough to feel reasonably confident at a terminal.

Linux shell terminalThe 'shell' is simply a program that lets you interact with the operating system (actually the kernel, to be more precise) ..

.. by taking your (text-based) commands and passing them on to the kernel. In my case, this kernel happens to be » Linux (which is but one variant of Unix).

The term 'shell' comes from the notion that this software acts like a 'layer' that sits between you and the operating system .. similar to the way an egg-shell sits between you and your hard-boiled breakfast.

The shell can be intimidating, cuz it uses a (text-based) command-line interface (CLI). No intuitive GUI to help you along. You either know the commands or you don't.

Didn't take me long to realize the CLI was where Linux's true power resides. When we upgraded the site, for example, to a Virtual Private Server, the support-techs who helped me with the move all used the command-line to work their mojo.

Most Linux distros do indeed come with an excellent GUI (usually either KDE or Gnome). But (but!) the Rad VPS does not. Which is why it became necessary to learn the Unix shell. (Something I tried to avoid.)

The Rad VPS is based on CentOS (Community ENTerprise Operating System), an off-shoot of Red Hat, which is probably the most popular of all enterprise Linux distros (.. and now a new member of the S&P 500, a development you may find telling).

GUIs (such as KDE or Gnome) require lots of memory/RAM. My laptop, for example, has 2-gigs, but the Rad VPS comes with an allotment of only 512-MB (.. upgraded from 384 just today).

With that limited amount, I need to run not only all the standard web applications .. such as Apache (web server), MySQL (database), Perl (scripting language), etc. but also cPanel/WHM.

So there's not much RAM left to run a GUI. [ Don't think I didn't inquire about installing a GUI. =) ]

Bottom line » if you wanna administer your own VPS, you need to learn the Shell. So that's what I'm doing. (Of course, there have been distractions, making progress uneven.)

••• today's entry continues here below •••

My weapon-of-choice (to learn the shell's CLI-mojo) is a Virtual Machine running Ubuntu Desktop (.. here on my laptop). Everything is done thru a program called a 'terminal' (.. or 'terminal emulator,' to be more correct), where my text-based commands are entered and executed.

So "learning the Unix shell" begins with learning the Unix shell commands, and what those commands do .. along with their associated options. For example, "cp" is the copy command. (One I use a lot.) "mv" = move, while "rm" = remove (delete). There are probably a couple-hundred commands, but only a couple dozen are really essential.

You may recall that Unix was developed in the 60's .. back when memory was sparse & expen$ive. So most Unix utilities (such as the copy and move programs) are small (<64KB).. especially compared to today's mega-monsters (.. such as Photoshop or Dreamweaver).

One of Unix's defining characteristics is its ability connect together many of its utility programs. The '|' symbol (called "the pipe") is used to "pipe together" two or more different utility programs.

This ability to "pipe together" any number of different utility programs (in a million different ways) is one of the things that makes Unix so powerful. Learning how to assemble these small-but-flexible programs in a myriad of ways is where a novice hacker (like me) starts to become a seasoned power-user.

Absolute vs Relative Directory Paths

One of the concepts I learned that has been particularly helpful is » "Relative vs Absolute Paths." An absolute path begins at the beginning, while relative paths begin based on where you are (.. your current working directory). Absolute paths always begin with a forward slash ( / ), while relative path never do.

Much of my shell-work (on the Rad VPS) is done in the /cgi-bin folder, where the YaBB and Movable Type scripts are stored. (Note: Unix uses the term 'directory' when referring to a folder.)

My /cgi-bin folder has an 'absolute' path of » /home/radified/public_html/cgi-bin. Once there (in the /cgi-bin directory), I may have to manipulate the directory » /yabb2/Members .. which means the absolute path becomes » /home/radified/public_html/cgi-bin/yabb2/Members.

Say I have to copy files stored there (which I regularly do). This means I need to enter both the source and destination paths .. so a CLI command can quickly become long enough to consume the entire length of my screen (1280x800). A single character mis-typed and it won't work. Or worse » it'll work, but work wrong.

But learning about how Relative paths work has allowed me to drastically shorten these commands .. to something like » "cp -r yabb2/Members yabb_new/Members". Voila!

All things considered, the hardest part of learning the shell has been » learning to use the infamous Unix text-editor » vi, which stands for VIsual editor. It's not pretty. Definitely not Microsoft Word. No formatting. No bold or italics. Text-only. Uses two modes » Command & Insert. Insert is where you actually modify the document. Command mode where you do everything else.

Shell scripting is another topic which might be complicated, because it involves programming.

I was considering throwing my notes into a new Rad guide .. "to the Unix Shell." But there are already plenty of Shell guides out there. We'll see .. since the hard part is already done.

Thanks to MrMagoo, who has been helping me fill in the gaps in my learning. (I appreciate it.)

Rule the World (for Free)

As a side note, I'm encouraged that Linux and so many other powerful software programs are offered for free (or as Open Source) .. created by volunteers who donate their time & expertise.

There's not only Linux (operating system), but also Apache (web server), MySQL (database) PHP (server-side scripting language), Perl (scripting language), Ruby (programming language), Rails (web development framework), Javascript (browser scripting language) YaBB (forum software), Movable Type (blogging software), and countless others. Learn to wield their power and you can rule the world.

For more along these lines, here's a Google search preconfigured for the query » unix linux shell bash command line learn

If you need/want a book, I heard this one (by Mark Sobell) is very good .. maybe the best.

« Previous Rad entry ||| NEXT Rad entry »

About this Entry

This page contains a single entry by Rad published on July 29, 2009 10:34 AM.

Reflecting on a Strange Coincidence was the previous entry in this blog.

Possum in my Toilet is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.