Introducing the command line - Part 1

Welcome to a new tutorial series where I'll be taking you for a spin around the command line so you can go from newbie to proficient very very quickly. The command line often scares a lot of people, and in the past it was virtually required to use a lot of things in Unix-based operating systems (like Linux).

This tutorial will be aimed at Linux users. However, much of the command line is the same throughout many Unix-based operating systems, including Solaris, all the BSDs and even Mac OS X (however, this does not cover Windows' command line as that is not based on Unix). All you need to do is load up your OS's terminal program (or just type away if your machine is text-based) to get started.

The command line is not scary. Tell yourself that now. In fact, it's under your command, as the name suggests. If you can tame it, you will end up more productive and you'll be tapping away instead of hunting for a command under menus, and sub-menus and you'll easily be able to automate boring tasks too.

Oh, by the way, if you hear me talking about the 'shell', that means I'm talking about the command line. It's just another name for it.

Interrogating the command line

OK, let's have a quick look at the command line now. Open your Terminal program wherever that might be (take a look under your application lists; it's usually under accessories, system or utilities). Here's what mine looks like.

Blank terminal window

At this point, it's at a prompt, telling you it's ready for instructions and waiting for you to tell it what to do. Let's deconstruct what the prompt tells us (yours might look different, don't worry about that for now).

[peter@blackhole ~]$

First of all, it tells me who I am. I'm logged on as peter (surprising or what?), so it's confirming to me that I am logged on as peter.

Next, it shows me the name of the computer I'm logged on to - in this case, that's the name of my main desktop, blackhole. Don't laugh. Seriously, don't.

After that is the strange looking squiggly line (or tilde) symbol ~. This actually tells me which folder I'm currently in (~ is shorthand for your home folder).

And finally, the dollar sign ($) tells me that the prompt is ended and it's time for me to get typing. When I do examples of commands, I won't write out the whole prompt. Instead, I'll just put the dollar sign followed by the command you need to enter. You don't type in the dollar sign (it's already there!), it just signifies that you should do that command when you have a prompt.

Your first commands

Isn't it about time we started telling the computer to do something, rather than just sitting there? Yeah, OK. Now commands are generally a sequence of words and funny-looking strange symbols and switches and scary stuff. Well, for now, we'll keep it simple and we'll just run a really quick and easy command.

The ls (that's a small L and a small S) command is short for 'list' and its job is to list all the files in the current folder.

Let's try it now. Type ls into your terminal, and press Enter.

$ ls

With any luck, you'll get a list of files and folders that are in your home folder.

Working directories

When you're working in the shell, you need to be aware of the following concept. Like in a file management application, you can only be in one folder at a time. While you're in this folder, you can work on files easily. The benefits of this probably won't make sense right now, but just be aware of this. Whichever folder you're working in is called your working directory.

To have the computer tell you which folder is currently your working directory, run the following command. It stands for print working directory.

$ pwd

And if you want to change which folder you're in, use cd followed by the desired folder. So, if I have a Pictures folder, I can cd into this folder like so:

$ cd Pictures

Likewise, I could also give the full path to the Pictures folder (/home/peter/Pictures).

$ cd /home/peter/Pictures

Going further

In Part 2, we'll be going a bit further and looking at some more command line stuff, so watch out for Part 2 (hint: subscribe below and you won't miss it!).

Ready to brave the next level? Read Part 2.

Part 2's not been written yet, but when it has, there will be a link here!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Introducing the command line - Part 1

  1. # Posted on 03 December 2006 at 03:08 AM

    [...] Welcome back, everybody. Once again it’s time to dip our toes in the ocean of geeky productivity that is the command line. If you haven’t already taken a quick look at Part 1, now’s your chance! [...]

  2. # Posted on 17 January 2007 at 06:50 AM

    [...] First of all, if you’ve got the beta currently installed, it’s important that you uninstall the beta version first. Open a terminal (if you don’t like the command line, go here for more help). Ubuntu users, please ignore the su - line and prefix the command after that with sudo. $ su - [[enter your root password]] # rm /usr/lib/mozilla/plugins/ [...]

Home » Articles » Introducing the command line - Part 1