Command Line for Dummies

Okay, so last time I talked a bit about what some of my close friends think about the Command Line Interface (CLI). This time, I'll try to introduce some of you Linux newbies to the art of CLI.

Arch Linux is a distro created by those guru-class Linux admins with tight deadlines. Therefore it had to be simple to set up and maintain, and blindingly fast. Now those gurus know what they are talking about when they say CLI is the best thing when you want those cahracteristics, so Arch Linux doesn't have a graphical package manager or any other tool of that sort that can be used for system administration (like control panels, and stuff like that). You use the excellent pacman package manager, and the good ol' text editor. Okay, since I'll be using Arch to demonstrate my points in this article, it would be best to at least familiarize yourself with it if you don't want to install and use it.

We all know that 90% of computer users are not system administrators. But what can CLI do for a casual computer user? What can it do that graphical environments cannot?

Chat

Every kid worth his/her salt nowadays uses at least one kind of online peer-to-peer (p2p) chat. Things like Google Talk, MSN Messenger, and IRC are common on most PCs. So how does command line make this any better?

Most people who have used IRC will know what commands like /join or /quit mean, but those are fairly obvious even to those who have never used them. Well, if you use Jabber, and that's one of the hottest things on the Internet right now, or Google Talk (which uses the same XMPP protocol that Jabber uses), you can use Mcabber to enjoy the same kind of efficiency that you have on IRC.

Mcabber, the command line chat client: One of the most efficient ways to chat, even if you don't believe me.
Mcabber, the command line chat client: One of the most efficient ways to chat, even if you don't believe me.

I will now talk about Mcabber in more detail, because the whole process of setting this thing up will be the best introduction to command line. Afterwards, I'll only briefly touch on other software, and let you explore the rest.

Let's install Mcabber first. It is not much in Arch. Just type in pacman -S mcabber in your console, and you're ready to go (well, to configure mcabber, actually).

Installing Mcabber on Arch Linux: Type pacman -S mcabber to install it.
Installing Mcabber on Arch Linux: Type pacman -S mcabber to install it.

It's almost like chatting with your PC, really. You say, "install mcabber, please", and he responds with "okay, it's this big, and it will be installed along with these, still want it?", "yes, please", "ok, here goes". Nothing to it really, for now.

Now let's connect our Mcabber. To do that, you need some information about your Jabber server. I will assume you youse Google Talk as your XMPP server instead of a real Jabber server.

For google talk, we use the server called talk.google.com. You will now observe the second important command line skill, and that is editing text. Some of you might be wondering why editing text is that much of a skill, or why it is so specific to command line. Well, you are right. Editing text is something we do daily, even if only in small quantities, and it is not specific to command line. But that's good, right?

Okay, we've heard some good news, and this shouldn't be hard. We need to create a file called .mcabberrc in our home folder. We'll use an editor called nano. It's a command line editor, but it behaves more or less like any graphical editor I know of.

The Mcabber team has provided us with a nice example essay on how to configure mcabber using mcabberrc. It's a file located in /usr/share/mcabber/mcabberrc, and we will simply steal all that and use it in our file. To tell your console to copy the file over to our home directory, you will say this: cp /usr/share/mcabber/mcabberrc ~/.mcabberrc. cp is short for copy and the following two parts of the sentence are the locations. It's pretty self-explanatory. Oh, and ~ is short for your home folder. Your Linux knows what it means, don't worry about it. ;)

Now the fun part. We edit the file. Tell your PC to install nano if you haven't already, and then tell it to open your file in nano. You can be pretty concise about. Just say nano ~/.mcabberrc.

Editing the .mcabberrc file: Remember, it's just like any editor out there.
Editing the .mcabberrc file: Remember, it's just like any editor out there.

Okay, now pay close attention. The essay Mcabber guys wrote is longish, but you only need a few things, not the whole thing. First of all, you'll notice that comments by editors is marked by a hash ("#") at the beginning of the line. That means "FYI" (for your information), and in most configuration essays you'll encounter lines like that that either give you an example, or the whole help for configuring your software. The lines that are FYI are meant to be read by the users, and the lines that are not are meant to be read by both the user and the software.

It helps to know a few things about how Mcabber understands the text, but FYI comments are there to help you with that. You can check out the Web for more information, and that's what this article is for, isn't it? ;)

Ok, let's get down to business. First, you need to find the line that says set user = and type in your username after the equal sign. Then go to the line that reads set server = and type in talk.google.com. If there is already a username or server name there, you will delete them first, naturally. That sets the username and server to reflect your needs. Then you scroll down (using the arrow keys, or Page Up / Page Down, naturally; no mouse here) to the line that sets the SSL access. It should say set ssl = somewhere. Set it to 1. Remember the talk about computers being all about 1s and 0s? Well, they are used here to mean yes and no respectively. So you say yes to SSL there. You also say no to SSL verification in the line below. The Google SSL certificate is kind of screwed up, so you simply say that you know it's Google, and it's okay to use it anyway.

That should be enough. To exit the editor, you press Ctrl + X (eXit), and then confirm that you want to save the file. It's just like closing any editor, except that you don't get a dialog, but a line near the bottom that says the very same thing about files not being saved, yada yada.

It's time to start mcabber for real. Those people with eagle eyes might have noticed that I actually lied to you. I have to admit I did. Since I already had the file called .mcabberrc, I creted another one, called .mcabbergt. I use Jabber usually, so I had to create a separate file for the other Google Talk account. The command I will use will be different from what you will use. You will most likely just call out mcabber by typing mcabber. I will use a different command, which is mcabber -f ~/.mcabbergt. The "-f" bit is called an option or an argument. Not only that I will be calling out mcabber to appear on my screen, but I'll also be asking it to use .mcabbergt file instead of what it usually uses, and that's .mcabberrc that you just created. Most command line software will understand a few arguments, and there are ways to find out what arguments they understand. For Mcabber, it's mcabber -h.

Help!: You can find out what arguments a command understands quite easily.
Help!: You can find out what arguments a command understands quite easily.

An interesting thing to note here is that people tend to forget that actual humans write software (though, some people think programmers are not humans), and that the text of FYI lines in configuration files, as well as manuals and -h information is all a form of communication between you and the developers. Not all programmers are good at explaining things, though. So sometimes you will find it difficult (if not impossible) to understand something. In that case, you should either try harder to understand (sometimes we are all just lazy or in a hurry), or find the programmer who did it and ask for explanation (maybe even offer to correct the text after you understand the issue better).

If you've called mcabber out already, you should be seeing something like the image below:

Mcabber is started and asks for password: It is customary that software doesn't show what you are typing while you type sensitive text like passwords.
Mcabber is started and asks for password: It is customary that software doesn't show what you are typing while you type sensitive text like passwords.

I've called mcabber with the usual mcabber command, so it is showing a different (non-Google-Talk) account. You should see your own account information there. Type in your password. You will notice that the cursor is not moving while you type the password, but that's exactly the point. You don't want your mom, looking over your shoulder to know what you are typing (and this feature is not limited to moms either). If you want a person to know your password, just tell them.

Now, let me show you how to get to know the language of Mcabber. Take a look at the screenshot a few blocks down the street... err... screen. The lower part has the status information consisting of two blue lines, the status messages between them, and input line below them. The top blue line tells you something about the currently selected buddy. The lower blue line tells you how your buddies see you. The status history will display background status changes (such as a buddy signing in).

You communicate with both your buddies and Mcabber using the input line. Now the important thing is that you use the same line for both these things. In a graphical instant messaging program, you would have to poke around (sometimes even two or three) windows to communicate with the same program. With Mcabber, you do it all there in that line (except maybe when you have more than one account, in which case you will have to open two Mcabbers).

Now when you want to talk to Mcabber and not your buddy, you will start the line with a slash ("/"). Mcabber then knows it's being spoken to. Otherwise, the message will be handed to your buddy.

Get help in mcabber, it's easy: Mcabber has full on-line help available at any time in the [status] screen
Get help in mcabber, it's easy: Mcabber has full on-line help available at any time in the [status] screen

Since Mcabber is not a human, you don't need to greet it with "/hi" or "/how are you". But you can still say things like "/help". Try it, and you will see something like the screenshot above. You can be more specific and ask about one command. Like "/help room".

To pick a buddy to talk to (assuming you already have buddies in your list), you will use Page Up and Page Down keys. Select a buddy, and simply type something. The text will appear in the right part of the window, which is used for talking to buddies.

I will leave you two love birds alone now, to get to know each other.

Playing Internet radio

Okay, now it'd be nice to have some music while we're chatting, right? Of course it would. Let's do that the CLI way, shall we?

First, ask your PC to install mpg123. Here's a refresher. You need to say pacman -S mpg123. That's our main man for Internet radio. (For offline music, I will show what Orpheus looks like).

mpg123 usues a sometimes funny set of arguments. You could say it's a loon. :) But I will show you how you can reach an agreement with it as to the language will use.

First let me tell you how to play Internet radio with it. Okay, so you need to tell it to read an url from a playlist file, and that you don't want it to shit itself if it encounters the rsync errors. I don't know what rsync errors are, but I know they can make mpg123 shit itself. So when you call for mpg123, you also add -y@ and the name of the playlist file (or if the playlist is online, the link to the playlist).

I found it a bit awkward to keep yelling "why monkey" (-y@) at mpg123, so I came to an agreement with it that from this point on, saying "radio" would mean "why monkey". That contract can be formulated like this:

alias radio="mpg123 -y@"

You can type that contract into the console directly, but that would not mean much. The moment you close the console, mpg123 will forget it ever existed. To make it permanent, you will use your trusted editor to edit a file called .bashrc, and type the contract in there. The exact location of the contract doesn't really matter, as long as it's on its own line. If you do this, you will have to restart the console, or load .bashrc. To load .bashrc, just ask for the file to be sourced (that's what loading is called) by saying source ~/.bashrc.

Now when you want to play a station, you type radio /path/to/playlist. Let's try this out. Try to play the Swissgroove station (my favourite!) at http://82.197.165.141:80. You can tune into any of the stations on Shoutcast.com this way, and it's all a matter of copying the URL to the playlist, and saying "radio http://my_url".

Other stuff

If you're new to CLI and you've come this far without a problem, you should be extremely proud of yourself. Even more so if you overcame any problems you had and successfully come to this section. You have just learned a great deal about CLI, and are mostly ready to explore it's beauty, thus becoming a Linux guru candidate. I will give you a few hints about where to begin.

For offline music, you can start with Orpheus, unless using MPD or mpg123 directly sound more fun (pun indeed intended). The orpheus looks like this:

Orpheus music player: This CLI program will make playing your offline music much easier than mpg123
Orpheus music player: This CLI program will make playing your offline music much easier than mpg123

If you want to manage files there is a powerful file manager called MC (Midnight Commander). It will shed some light on your numerous files and folders. It's a great tool, but I prefer learning all the commands to talk to files (like the cp above). Sometimes it is convenient to use MC, though. Here's how it looks:

MC is the MC for files: this file manager is one of the most powerful ones on Linux
MC is the MC for files: this file manager is one of the most powerful ones on Linux

There are many more CLI tools that can make your life easier (yes, even easier than those fancy-looking graphical tools), but I'll leave all the exploration to you. Hope you've enjoyed this. Leave a comment if you don't understand this of if you've found something nice, and I'll fix this article accordingly.

Post new comment

The content of this field is kept private and will not be shown publicly.

Powered by Drupal - Design by artinet