Skip to content

Instantly share code, notes, and snippets.

@tmcdb
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcdb/62f616303b09918dcfcf to your computer and use it in GitHub Desktop.
Save tmcdb/62f616303b09918dcfcf to your computer and use it in GitHub Desktop.

#Command-line Basics

This is an introduction to the command-line interface. It's for complete beginners.

#####This is for you if you are interested in...

  • Learning to code
  • Becoming a developer
  • Making a website from scratch
  • Finding out about:
    • code
    • coding
    • programming
    • development

What is "command-line"??

You may have heard of it but it has many names; I'm talking about that little window with an old fashioned looking cursor and not much else.

Some aliases for the command-line include (but are not limited to):

  • terminal
  • tty - for telly-typewriter (really old fashioned but quite cute)
  • prompt
  • commands
  • shell
  • bash
  • CLI - for command-line interface

Terminal

It's an incredibly useful tool. Here's why.

Software

Normally, when we interact with our computers as non-technical users, we do so via application software. We've all used applications before – I mean for example web browsers like Safari and Internet Explorer, or word processors like TextEdit and MS Word. These are computer programs designed to help us perform an activity but there are activities that are a whole lot easier to achieve using software of a different nature.

The nature of applications is GUI-based. GUI stands for Graphical User Interface. Describing a GUI to the computer literate feels a bit like telling a fish about water – it's the visual bit of the program; what you see, click, tap, drag-and-drop and scroll on. GUIs basically are computers as far as we're concerned as non-technical users.

By contrast the nature of a command-line interface is text-based. A command-line interface provides a means of interacting with the computer via typed commands. A typed line of commands, or a command-line, can be a very powerful way to perform activities with a computer and as such is a very useful and time-saving tool for programmers (coders, software-developers, web-developers).

A command-line interface describes a way of controlling programs or the operating system of a computer through typed input. The interface is usually provided by a program called a shell.

Shell

A shell is a command interpreter program. For us to use a shell program we have to open a terminal emulator application and run the desired shell program.

Terminal Emulator Software

Terminal emulators are the applications that provide a terminal window for displaying the commands as you type them and any output from programs you run via those commands. Examples include Terminal and iTerm for Mac OSX and Command Prompt and PowerShell for Windows.

Bash is the name of a shell program that runs by default when you open Terminal on a Mac. Let's take a look at that as our example.

Using Bash

Upon opening a terminal window with Terminal we're presented with what's know as the prompt. The prompt is a sequence of one or more characters that indicates that the shell program is ready to accept a command. The prompt can contain all sorts of useful information and will look different depending on the shell that's running. It can also be configured easily by the user. Here's what the default Bash prompt looks like in Mac OSX's Terminal.

Prompt

Tutorials like this one often present code or commands in a distinctive, familiar and readable format. Here's an example of a command line.

$ cd ~/Sites/my_new_website

In the example above the prompt is a single dollar sign $, the command is cd and it takes one argument – a pathname.

Commands and their arguments

A command executes a program when it's input into a CLI. Normally commands are short words that name a program or describe its function (or both).

$ cd              # change directory
$ mkdir           # make directory
$ pwd             # print working directory
$ ls              # listdirectory contents

These are some of the most commonly used commands for navigating around file systems. More complex and powerful commands are available for finding, moving or altering files and folders and executing code, or connecting to the web to download and install software.

$ mv              # move files or folders
$ rm              # remove files – **potentially dangerous**
$ ruby            # execute ruby code
$ curl            # transfer data from or to a server

These commands all take arguments. Passing an argument to a command alters its behaviour. They also accept option flags which further alter the behaviour of the programs.

The rm command is a dangerous one. There's no undo in a CLI, breaking changes are often irreparable so be careful. Avoid using rm until you're comfortable. Use the trash in your OS's GUI for removing files and folders.

Glossary

Process

A process is an instance of a computer program that is being executed.

Argument

Arguments are pieces of data that are handed to commands or functions. They appear after the name of the program / function / command, sometimes surrounded by parentheses.

Parameter

See argument.

Call

When code is excecuted often is said to be called or invoked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment