One of the earliest essential skills for programmers is to know and be proficient with the command line interface. Getting started with the command line interface feels a lot like learning to ride a bike for the first time. You will get super frustrated, but please stick with it, as this skill will be super rewarding in the long term. ¬†I promise at one point, you'll hit your "Whoa ūü§Į, I had no idea my computer could do that" moment.

A brief history of the Linux operating system

The story behind Linux is super interesting and motivational for any coder. Sometime in the very early 90's, Linus Torvalds, a young coder and hobbyist, really wanted a UNIX based computer, but was too broke to buy one.  

Unsatisfied with the operating system on his PC, he started hacking around with the basic capabilities on the processor itself.  What began as curiosity, soon turned into a full UNIX like operating system.  

In August of 1991 Torvalds decided to share his project with the world:

From: [email protected] (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Message-ID:
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki

Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones. This has been brewing
since april, and is starting to get ready. I'd like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system (due to practical reasons)
among other things).

I've currently ported bash(1.08) and gcc(1.40), and things seem to work.
This implies that I'll get something practical within a few months, and
I'd like to know what features most people would want. Any suggestions
are welcome, but I won't promise I'll implement them :-)

Soon after, the kernel quickly gained traction as one of the internet's first free and open source, virally developed softwares.  Coders and hobbyists from all over the world continue to contribute to this free and open software, turning it into a cornerstone operating system, that has built much of the software industry as we know it today.  

Torvalds went on to create git in 2005, and continues to support the Linux Foundation. At some point along the way, he was invited by Steve Jobs to join a lucrative career at Apple, but refused as he would've been forced to abandon his free and open source software projects. Linux and git are the pillars to just about every software and app that we use today. ¬†Congratulations, as you are now joining the many coders and hobbyists within the git and Linux communities! ūü§ď

Setting up your system for Linux

Step 1 is to get a Linux terminal up and running on your computer.  How to do that can vary depending on your computer.  Google is your teacher in this endeavor, but here are a few hints:

Using the Mac OS X Terminal

The Mac OS X Terminal is not exactly Linux, but is pretty much the same thing.  You can find it in: Finder > Applications > Utilities > Terminal

Using a Chromebook

The Chromebook is a surprisingly powerful development tool, so long as you're ok with kicking it into developer mode.  Try this tutorial to get up and running.

Using a Windows Computer

Start by buying a chromebook and follow the steps above (ūüėä). ¬† Or, here are instructions that you can try out for Windows.

Other Options

If you are struggling with a unique and testy computer, you can try using a remote option.  Services like Amazon AWS allow you to log in to one of their remote computers from your computer, and use a standard version of Linux or Ubuntu. Unfortunately, we can't provide instructions for every system, but if you keep googling and hacking away, you'll eventually make this work.

Now that you have your terminal up and running, start by taking a look around.  This is basically the text version of your entire computer.  You'll start off in your root directory (really just a top level folder in your computer).  

Start by taking a look in that folder by typing: ls and pressing Enter.

ls

[your files and folders will show here] 
Example output: Desktop Downloads etc

ls - short for list,  lists out all the files and folders in the directory that you are in. Files are generally shown with their extension (i.e. .txt, etc.).  Folders usually have no extension.  

Now let's move around your directories.  Choose one of the directories listed from the ls output.  

Now type:  cd your-directory and press enter (replacing your-directory with the actual file name).  Example:

cd Desktop

If your directory has a space in the name, put the entire name in quotes.  Example: cd 'your directory'

Once in that directory, you can look around again by typing ls.  You may wander into your desktop and see a familiar output, as all of your desktop files will be listed.

After doing this a few times, you may wonder how to get back from here.  Here are a few helpful options with cd:

  • cd Typing this alone will take you back to your root directory
  • cd .. Will go up one directory
  • cd directory1/directory2 Can go down multiple directories
  • cd - Will go back to the last directory you were in

Installing, Reading, Writing, & Deleting

Time to install our first text editor!  Text editing (with tools like Microsoft Notepad) is one of the most basic things you can do with a computer, and yet is what all code is built from.  Nano is a very simple and open source text editor that can run from the command line.

Install Nano for Mac

First install Homebrew, if you have not already.  Homebrew is a tool that helps you install software publicly available online through the command line.  Learn more at their website.  

Enter the following into your terminal to install:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Now you can use brew to install Nano by entering the following:

brew install nano

Install Nano on Ubuntu

Apt is a built in tool that helps you install publicly available software online.  Enter the following into the terminal to install Nano:

sudo apt-get install nano

For Other Systems

Google how to install Nano on your system, and start the process of trial and error ... ūü§∑‚Äć‚ôāÔłŹ

Creating A File

Now that you've installed Nano, you can make your first text document.  Using your terminal navigation skills from the prior section, see if you can navigate to your desktop directory.  Use ls to see the files in your current directory, and variations of cd to move in and out of directories, until you find the one that looks like your desktop.

Now, create your first file by typing:

nano "hi-world.txt"

A screen should open, which is your text editor. You can type whatever notes you like here. One thing that may frustrate you is that your mouse will not work in nano or the command line.  It's like stepping back in time to pre-1984!

Instead, when ready, type Ctrl o  to output (or save) the file.  

You'll see a message near the bottom of the screen, confirming the file name to create. Hit Enter to save the file. You should then see the new file pop up on your desktop, which you can open.

Congrats!  You just wrote your first file.  Nano can be challenging at first, as it involves using commands.  If you don't know how to do something (for example, how do I get out of Nano?), just google around.  In the example just mentioned, press Ctrl x to exit.

Copy Your File

Now let's make a copy of this file.  You should be fully exited out of nano and back in your command prompt.  If not, hit Ctrl x to exit nano.  You may be asked to save the file.  If so, type y and Enter to confirm the file name.

To make a copy of the file you just created, into a new file called "bye-world.txt," type the following:

cp hi-world.txt bye-world.txt

In the above command, cp is short for copy, and you then just follow that with the existing file name, followed by the new file name (separated by a space).  If your file name has a space in it, wrap it in quotes (example: 'bye world.txt').

You should now see the second file on your desktop named "bye-world.txt," which you can open and see the same output.

Create A Folder

Now let's make a folder called "universe."  To create this folder, we'll use the mkdir command (short for make directory). Type the following into the terminal:

mkdir universe

You should then see the new folder on your desktop.

Move A File

You can move a file with the mv command.  Let's move "hi-world.txt" into the "universe" directory by typing the following:

mv hi-world.txt universe/hi-world.txt

You should now see that "hi-world.txt" is no longer on your desktop, and now in the "universe" folder.

Delete A File

To delete a file, we use the rm (remove) command.  Type the following to delete "bye-world.txt."

rm bye-world.txt

You should now see the file is gone.  NOTE: Use the rm command with caution as this pretty much fully deletes the file from your computer!

Delete A Folder

To delete a folder, we use the rm -rf command (the remove command with recursive and force options).  This will delete your directory and everything inside. Type:

rm -rf universe

Your folder should now be gone.  NOTE: Again use this command with caution, as your folder is gone for good.  Does that scare you?  No worries, that is where git comes in, which we'll learn in the next article.

Here's A Cheatsheet For All The Commands We've Just Learned

  • ls - lists files in directory
  • cd (your-directory) - changes into directory
  • cd .. - goes up one directory
  • cd - - goes back to the last directory you were in
  • cd - goes back to your root directory
  • nano (you-new-file) - to create a text file with nano
  • cp (current-file) (new-file) - copy a file
  • mkdir (your-new-folder) - makes a new folder
  • rm (your-file) - deletes a file
  • rm -rf (your-folder) - deletes a folder

One other helpful tid-bit.  Pressing the up key will take you back to any of your prior commands.  Give it a try!

There are many other commands, which you'll begin to uncover when you need them. As always, when in need, google it.  

Final Thoughts

Why the command line and text editors matter? Because software development is basically just text and commands!

Yes, there are nicer text editors than nano, but nano is a great place to start, and still useful for terminal outputs. We'll explore different editors in articles to come.

As you start to use the command terminal more often, you'll wonder how you ever worked without it.

Finally as you have questions, to quote a podcast from @garyvee - "google is your mom now!" ¬†Or, just leave them in the comments below. ¬†ūüôā

Next Up

Next, we provide an intro to git and GitHub, both essential tools for web developers.

This article is part of an ongoing series to help you build your first app.  Subscribe below if this content helps you!