If you’ve ever wanted to get behind the graphical user interface (the GUI, pronounced “gooey”) of your computer and see a little more of what’s going on, you should explore the command line. What is the command line? If you’re like me, your first exposure was probably the black terminal screen and garish green pixelated text of MS-DOS, a blinking cursor flickering after the
A> (it took my family a while to get a Tandy with a harddrive!) or the
C:> prompt. In this series, though, I’m exploring some root functionality in a Unix environment.
Basically, the command line–or the command line interface (CLI)–is an interface through which you can, using a variety of text-based commands, do what programs on your Windows, Mac OS, Ubuntu (and so on) interface allow you to do visually. You can move files around, unzip archives, un/install programs, make programs, run programs, download, upload, and so on–providing you’re in the right place, have any necessary Internet connection, enjoy the right user privileges, and have the right tools at your disposal. In an earlier command line case study, I discussed my adventures with
cp; this is one of the commands you would be running if you were using
CTRL-P to copy files between two folders. Anything you could do with a mouse click or by dragging and dropping, you can do from the command line–if you know how!
Most of us are using GUIs to interact with our computers, so I’ll assume that’s the case here. To access your local command line, you want to find the “terminal” program and run it. Different operating systems will put this in different places; sometimes hotkeys are pre-associated with it (CTRL-ALT-T sometimes works), sometimes it is already docked in your main menu, sometimes you have to hunt it down in your file structure. You can add a hotkey, if one doesn’t already exist.
Terminal will open to your own local machine–you’ll have to use a protocol like ssh (secure shell) to get into your server, and we’ll go over that, too. When I open terminal onto my local machine, I see the following prompt–though yours will look different!
The prompt above is my default–you’ll see my username, and then where I am–on the computer called Sam. This is the local hostname. If you change any of this information in your settings, it will change here. You can also change things manually; I won’t go into this, becuase it’s not really necessary at this point, and there are lots of good tutorials online (just google
change terminal prompt ubuntu–or some similar set of terms). Before we get started, though, I want to introduce you to the
This is an indispensable command in terminal, especially for beginners–it stands for “manual,” and using it in combination with known commands (you can google many good lists of unix commands, but you do have to know what the command is before you look it up) gives you an account of the command, the different flags or qualifiers you can use with it to achieve specific results, and so on. For instance,
man ls will give me the manual page of the command we’ll explore below,
manpages are longer than one screen can display. So, to advance page-by-page, press the
space bar. If you’ve read enough and want to escape the
man, you can escape by quitting it–just type
q. This is usually the way you escape, so when in doubt, hit
You should be noticing by now that unix commands are essentially radical truncations of pretty-much everyday language. Now–let’s explore our surroundings!
In terminal, type
ls. This will list the current directory contents, at a very basic level–you’ll see a table of all the visible subdirectories and files, typically color-coded according to type. However, there are lots of ways you can see more fully into your directory contents using ls! You can read all about the full functionality of the
ls command in its
man page, but here are a few more specific commands that I like.
You might have noticed with the first
ls you ran that the list of files and subdirectories seemed rather brief and uninformative. That’s true–basic
ls only gives you that information. If you want to see everything in the current directory, including hidden and system files, you need to lIsT -aLL, using the flag
-a. Of course, you may not be able to read everything here, and it still won’t give you all the information you might want–like who owns the folder, what kind of permissions are associated with it, when it was created or updated, and so on. To see everything everything, use a command like this:
ls -a -l |less
What’s going on here? We’ve got a handle on the command and the first flag. The second flag,
-l, will allow you to view the lONG version of the output. Okay–makes sense. What about the vertical line and the
less? The vertical line is called a pipe, and it does what pipes do–pipe one thing into another. Here, we want to pipe the output of the too-long directory listing through another command, called
less. You can read more about
less, as you can with all commands, in its
man page. Neat, huh? The pipe is a powerful tool, but I don’t know too much about it–maybe I’ll learn more and write a post about it sometime in the future….
How do you move around in these directories and subdirectories? With the command
cd, or cHANGE dIRECTORY. You can
cd to any existing directories in your file system. Once you’ve changed your directory, notice that your prompt may change, at least on your local machine. On a server, that may not happen, and so you’ll need the command
pwd to pRINT THE wORKING dIRECTORY. More about that later. Here are some ways to use
In order, what I’ve done above is
cd to the subdirectory
Pictures; then back to my original location with the
.., which signifies back one level in the directory structure. Then, I dug two subdirectories down into
Pictures; then, I backed two levels out and moved into the subdirectory
mkdir & rmdir
What if you want to make a new directory? Use
mkdir misc to–you guessed it–mAKE A NEW dirECTORY CALLED misc. You can probably use the forward-slash and the .. to make new nested directories, too. Let’s try!
Yes, it works! Now, let’s delete that empty
test directory so we can reuse the name.
rmdir test// reMOVES THE EMPTY dirECTORY
cd Birds// cd to another directory parallel to
mkdir ../Pictures/test// makes a new directory called
testone level back and inside the directory
Pretty cool, huh? Now, let’s see what your server looks like.
To get into your server, you’ll need to use a command like
ssh–or sECURE shELL–to tunnel to the server via an existing and open Internet connection. I have a server at
cerosia.org that I can access with my username,
howe and my secret password, which I’m not going to share w
ith you. Here's how I get there:
I will be prompted to input
firstname.lastname@example.org's password, which I do, and I’m in–after some information about where my server is, what system it’s running, last login time, date, location of last login, and so on. Once you’ve successfully shelled into your server, you’ll notice that the prompt looks a little different.
The basic structure is the same, which can be confusing for some new users; my username, and then where I am–at a host named li301-8. This is why you might want to change the look of your remote prompt!
Now you’re here, you can pretty much use
rmdir, and other commands in the same way.
I hope this lengthy narrative gave you a good sense of how to move around in your directory structures, whether local or remote, in addition to answering some more fundamental questions that tech-oriented tutorials assume you already know. Next up: creating, viewing, editing, and saving files on your server. Or maybe, changing your prompts!