Normally, I don’t write stuff like this, but Qian asked me for a reference of basic shell commands and I got really depressed about what I found. This page (top 10 linux commands for newbies) has over 1000 diggs, and what’s in it’s top 10? vi ! are you kidding me? Yea, that’s sure a sure fire way to send someone crying back to Windows or OSX.
Part of the reason why computers remain so inaccessible to the vast majority of people is that it is a extremely difficult task to write documentation from the perspective of a user who doesn’t know anything about what you’re trying to tell them. In another shocking example from the above linked page, the author throws out words like “wildcards” and “pipes” without giving any explanation what they mean.
Sure, people can figure things out by experimentation, but the author seems to forget that the vast majority of newbies are hesitant to issue commands they they don’t understand, not just because they don’t know what’s going on, but out of fear that they’ll somehow screw something up, because they don’t know what’s going on.
That’s an entirely reasonable reaction. I mean, what if someone just told you to go change that thingamajiggy to a whatchamacallit in that power generator over there. Would you just go in and do it without having any idea what’s going on. With no hesitation?
Anyhow, enough ranting. Here’s my list of top (maybe 10) shell commands that “newbie” users should get used to.
But before I start, lets start with even more basic terminology. What is a “shell”? The term shell actually refers to something quite abstract, and most people don’t even bother explaining that.
Computer scientists love metaphors. They use metaphors to describe all kinds of complex relationships of various pieces in a computer system. “Shell” is such a metaphor.
If you imagine your computer software a being composed of many layers, like an onion, the “shell” is what is on the outer most layer. It is the layer that you, as a user, interact with. So when you’re typing in commands, you’re typing them into a piece of software known as the “shell”.
Ok, now that we have that out of the way, here we go:

  1. pwd: Oh yea, computer scientists also love acronyms, and shortened forms of words and phrases. That’s because they type all day, and shorter forms mean less typing.
    Anyhow, pwd is short for “print working directory”. A “directory” just refers to a location on your computer. In Windows and Mac term’s it’s a folder. When the shell program is running, it’s always running in a directory, and the directory it’s running in is called the “working directory”.
    On most Unix-based systems (where you’re most likely to encounter a shell), a directory is identified by it’s path. For example on my system, I may do something like this:

    % pwd
    /home/ken
    

    In this example /home/ken is what identifies my current working directory. The slashes in the path denote different levels of the hierarchy. Directories can contain other directories (just like folders contain folders)

  2. cd: This command is again, shorthand for “change directory”. It let’s you change the shell’s current working directory to something else. You use it by specifying the directory you want to change to after you type the command name. For example:
    % pwd
    /home/ken
    % cd /home
    % pwd
    /home
    

    You can see in this example that I first print my working directory, then I use “cd” to move to the /home directory, and then I print it out again to show that it has changed.
    You can also use cd to move to a directory that’s located relatively to your current working directory. Let’s say my directory /home/ken contained a directory called “foo” (“foo” is the favorite example name used by computer scientists). I could do something like:

    % pwd
    /home/ken
    % cd foo
    % pwd
    /home/ken/foo
    

    You can see that in this case, I moved to the “foo” directory inside the /home/ken directory, but I didn’t have to specify /home/ken/foo in it’s entirety. In this case “foo” is called a “relative path”, because it is interpreted relative to my current working directory.
    Now there is a special relative path .. that refers to the directory containing the current working directory. With this, you can move up the hierarchy without knowing the name of the directory above you.

    % pwd
    /home/ken
    % cd ..
    % pwd
    /home
    % cd ..
    % pwd
    /
    

    In this example, I move up one directory level at a time, using the special .. pattern. Incidentally, the path with just “/” is called the ‘root directory’, and it is the highest point of the hierarchy. Issuing a “cd ..” at this point would result in nothing, since you can’t go any higher.

  3. ls: Ok, so this one isn’t quite an acronym, but it’s pretty close. “ls” stands for “list”. Get it? No? Ok, whatever, doesn’t matter.
    ls is used to view the contents of a directory. A directory, just like folders, can contain files, as well as other directories. Since your computer has many thousands of directories, it’s not likely that you’ll know how to get around without being able to inspect each directory. That’s where ls comes in. It’s usage is pretty simple. Just type ‘ls’ and return:

    % pwd
    /home/ken
    % ls
    foo
    myfile.txt
    

    That’s it. You can now see that the /home/ken directory contains “foo” and “myfile.txt”. Hurray!

Ok, that’s all for now. Why you ask? well because this took longer that I thought, and also because these are the three basic commands that you can use to your hearts content without fear of screwing anything up. So try anything you want to and experiment. As long as you don’t mis-type the command, it’s impossible to do any damage.
There’ll be more in following posts, but if you’re really impatient, you can look at something like this reference, which is somewhat better than what I linked to at the top of this post, but still pretty terse.

Leave a comment

Your email address will not be published. Required fields are marked *