# The Command Line

Somewhere around 1969, someone decided to replace the printer on their teletype computer terminal (known as a TTY,) with a cathode ray tube, giving birth to the “Glass TTY,” perhaps the first truly modern computer interface.
With the Unix kernel came some of the first modern command line interpreters, or “shells.” In 1971, Ken Thompson created “sh,” also known as the “Thompson Shell.”
In 1979, Stephen Bourne created the “Bourne Shell,” which was generally replaced with the “Bourne again Shell,” or “bash” in 1988. Bash is still the most commonly-used shell, thirty years later,
Shells are how you interact with the part of your operating system that talks to the hardware. In your shell, you can run commands, inspect processes, write scripts and use character-mode programs.
It’s also the most efficient and powerful way of interacting with your computer.
In your shell, programs are generally written to adhere to certain principles, summarized by Peter H. Salus in A Quarter-Century of Unix (1994):

Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams, because that is a universal interface.

Unix-like programs take text as input and give text as output wherever possible. They don’t require extraneous interaction by default, as this would limit their usability in scripts.
They work with pipes. What are pipes? Pipes (Implemented with the character “|”,) connect commands and programs and even let you string together lots of them, to create powerful ad-hoc programs known as one-liners.

## Getting Started

In Linux, start with the default terminal. It might be gnome-terminal or mate-terminal, but it will probably be under ‘Accessories’ or ‘System Tools’ in the OS’s menu system.
On a Mac, it’s in “Applications/Utilities”.
In Windows, you should download “Git Bash“ and install it using the default options. (Windows’ built-in command interpreters, cmd.exe and PowerShell, are not good alternatives–you really need Git Bash.)
Your terminal prompt promamly looks something like this:
jim@host:~$ - That’s your username and host (computer’s) name the current directory, (~ is shorthand for the current user’s home directory,) as well as a dollar sign ($) prompt. This prompt means that the shell is ready to accept your typed commands.
In Bash, the shell, or command interpreter, the core commands are given the shortest names that still avoid ambiguity. This dates from the days when disks were small and networks slow, but it works well for users now, with a little bit of memorization.

## pwd - where am I?

To see where you happen to be in the filesystem, you type pwd and hit enter. On my system, this gives me:

The command pwd stands for “Print Working Directory,” though I have it memorized as “Present Working Directory.” Either works, so memorize it with whatever mnemonic that works for you.

## Show me the files: ls

ls is another one like that–officially, I believe it stands for “List Files,” but years ago, I was told to remember it as standing for “Let’s See.” Let’s see what’s in the current directory:

That shows us the filenames, but doesn’t tell us much about the files. It also doesn’t show us hidden files. (In Linux, the shell hides filenames that begin with a dot. “.”)
To show more information, we start adding “option switches” to ls. To show all the files, add -a to make it ls -a:

See all of those “dot” files that we didn’t see before? Still, we don’t know what kind of files they are. Rather than go through all of the options we can add, I’m going to give you one easy-to-remember option set that tells you most everything about the files:
ls -a -l -g -F
Wait, that’s not very easy to remember, is it? Well, we can combine all of those options into:
ls -Flag
It is not the word “Flag,” just a convenient way to remember those options. Here’s what it gives us:

You can also add the name of a file or directory to the command:

Try it out. ls doesn’t change anything about the filesystem, it simply lists what it can, so it’s safe to play around with.

## Change Directories with cd

This section is being expanded in Getting Around.
cd stands for “change directory.” So, to cd to your system’s temp directory, simply type:cd /tmp
To quickly go to your home directory, type cd by itself.

### A Note on Directory Shortcuts

The operating System has a few special ways to work with directories that are worth looking at now. To illustrate, let’s create a new, empty directory and show what’s in it:

(In the example above, any characters after the # is a comment and is ignored by the shell.)
As you can see, there are a couple of pseudo files listed, ./ and ../ that refer to the present directory and the parent directory, respectively. They might seem confusing at first, but they are quite convenient, especially when writing scripts.
The other directory shortcuts to know about are / and ~/.
~/ is the current user’s home directory.
/ is the system’s ‘root,’ or top-level directory. (/ is the top level, regardless of what disks or partitions may be mounted, which may not be obvious if you’re coming from MSDOS.)

### Using . and .. and /

Using cd, you will frequently use ../ to jump up a directory, or even several: cd ../../../
You can jump up a directory and then down a different path:

As you can see, by using cd ../../views/partials/ I was able to go up two directories and down two others. Very handy.
Using ./ for the current directory is equally handy. Let’s say you have a file in /tmp that you want to copy to the current directory. This is easy, using .:
jim@blinky:~/foo\$ cp /tmp/foofile .
As you can see in the above example, I referred to the temp directory as /tmp to show that I mean the one in the top level. Without the slash, bash would try to find it in the current directory:

That’s no good. Let’s add a slash:

# Note:

Unix (and Linux and OS X’s BSD subsystem and even Windows’ Git Bash) are case-sensitive and picky about things like slashes. Don’t let it intimidate you!