Tag Archives: BASH

She sells seashells by the seashore. Well, yes… that may be true, but that’s not the type of shell we’re going to talk about here today.

I’m going to talk a bit about the Linux shell. What is the Linux shell? What does it do? How can I interact with it on my GNU/Linux operating system? Those are all good questions. While today’s most popular distributions of GNU/Linux are morphing into operating systems that are more and more graphic user interface oriented, the real power of Linux still resides in the command line.

When you boot up your Ubuntu or Mandriva GNU/Linux operating systems, most of you see a graphical login screen. Others, like myself, might see a non-graphic command line login. Both do basically the same thing. They log the user into the Linux shell so that he may begin to utilize his system’s potential to perform tasks. That’s what we do with our computers, regardless of what the tasks happen to be… emailing pics to auntie Myrtle or hacking cloud and cluster security systems.

The Linux shell is the interface between you in that seat in front of your monitor and the operating system that controls the hardware in that box under the desk that does the actual stuff you want done. There are numerous shells in Linux; the most commonly used one is called BASH – Bourne Again Shell. You’re in the shell anytime you’re logged into your GNU/Linux operating system; whether you’re interacting with it graphically or from the command line.

Graphic User Interfaces or GUIs are just “front ends” to applications that are running in the shell. I’ll be talking mostly about the non-graphical command line interface here today, though. You can access your command line interface from within your GUI by using the graphic front end application for the command line provided by your desktop environment. For example, in Gnome, you could use Gnome Terminal; or in KDE, you could use Konsole. Either way, these are both just graphical front ends for the BASH shell command line.

When you first login, you’ll get what’s known as a prompt. It is just a blank line waiting for your input (commands). It’ll look something like this:

joe@mysystem:~$

The first part, “joe”, is just the user’s login name. “@mysystem” is the name of the computer the user is logged into. The “~” character tells us that user Joe is working from his home directory. The “$” character is the standard character denoting a non-root, regular user.

Let’s say Joe wants to list all the files in his home directory. All he has to do is type:

joe@mysystem:~$ ls

This command, known as “list”, tells the shell that user Joe wants to see a list of all the contents of his home directory. The shell immediately responds after Joe hits the Return (Enter) key on his keyboard with this output:

It looks like Joe has five regular directories, a Dropbox directory, and the directory that contains his desktop icons. In reality, there are more directories and files in Joe’s home directory, but they’re what are known as “hidden” files. Their names are usually preceded by a .(period) to make them hidden. If joe wants to see all his directories and files he can list them this way:

joe@mysystem:~$ ls -a

The “-a” option means all. The list command will list all items in a directory when using the -a option. Joe’s list now looks something like this:

The above directories are hidden by the preceding .(period), as mentioned above.

Let’s say Joe want’s to create a grocery list for his afternoon shopping chores. He can do this via the shell and command line also by using a command line editor such as vim. He would first do this by bring up the vim application in the command line interface:

joe@mysystem:~$ vim groceries

This command would initiate the vim application using a new file called “groceries”. Vim or Vi-Improved, as it’s known, is a non-graphical text editing application. It would look something like this to Joe:

lettuce

tomatoes

catfood

peanut butter

eggs

milk

bread

~

~

~

–INSERT– 10,1 All

Once Joe had finished typing out his grocery list, he would save it using the vim command :wq, which would also close the vim application and bring Joe back to the command line prompt. He could also print his list from the command line like this:

joe@mysystem:~$ lpr groceries

The lpr command would tell the shell that Joe wants to output the contents of the groceries file to the printer. The printer would receive the data and the command to print from the computer’s hardware and begin printing Joe’s grocery list.

All of this we’ve talked about today doesn’t even scratch the surface of the power at your finger tips when using the Linux shell. Your first step should be to read the Linux manual page for the BASH shell. There is some very useful information in that document. Stay tuned here… I’ll come up with some other lessons in the future. Remember what I always say…

2010 is shot in the arse. 2011 is right around the corner. Here’s what I resolve to do Linux-wise for the new year:

I want to try to continue to give back to the Linux community the knowledge and insights that I have garnered while interacting within that community for the past 4+ years.

Linux should be all about community. While there are many friendly MS Windows and Apple/Mac support forums and communities, it’s doubly important for Open Source and GNU/Linux to remember that much of its success and evolution is driven by its faithful community. We should all resolve to be more helpful in 2011; and not just regarding Linux.

I want to learn to use the grep command more efficiently.

Grep is a command line tool that can be used to find lines in a file using regular expressions. I confess that most of the time when I use the grep command it’s because I’m copying someone else’s recommended command into my terminal. I want to learn more about how the command works and where best to use it.

I want to learn a bit about shell scripting, particularly BASH shell scripting.

Shell scripts are little programs that can be written to perform a series of commands within the shell. They can be quite useful. I’m interested in learning the basics of BASH shell scripting.

I want to install and experiment with at least one distribution that I’ve never installed before.