Jon Stuebe

Front End Tools Pt. 1 (Terminal Basics)

terminal tips

Front End Tools Pt. 1 (Terminal Basics)

Posted by Jon Stuebe on .

terminal tips

Front End Tools Pt. 1 (Terminal Basics)

Posted by Jon Stuebe on .

This article is part one of a series on Front End Tools.

Before jumping into using Node to install our tools, I want to give a brief overview of how to use terminal to accomplish the following steps. If your already familiar with terminal, then feel free to skip to the next article in this series.

Using terminal or the command line can seem overwhelming at first. But I promise you with a few different commands in your bag of tricks it will quickly become more manageable.

Sorry to all of you windows users, but for time's sake I'm only going to go through how to use terminal on a mac or linux and not command prompt. However, if you install git on windows it comes with git bash will be fairly close to the directions I will be giving.

Before I jump into the commands section the first thing to know is that when you see me write the code snippets with a dollar sign ($) before the commands that is simply to show the start of a line in terminal. You will not need to write the dollar sign. If you do, the command will not work.

Changing Directories "cd"

So to jump right in there a few commands you will need to know to get navigating around to your files and running commands. The first is "cd". It stands for change directory. The syntax is as follows:

$ cd <directory_path_goes_here>

An real life example make look like this:

$ cd /users/jonstuebe/sites/testing/

However, while the above would work (permitting that the folder testing exists), most people prefer to use the "~" symbol to denote the "home" folder on a mac. It simply saves you time. Using the tilde symbol the above would be shortened to the following:

$ cd ~/sites/testing/

Now that your familiar with "cd", let's talk about creating, moving, and deleting files and folders.

Creating a New Folder "mkdir"

To create a new folder you use the command "mkdir". It looks something like this:

$ mkdir testing

Keep in mind that it will create the folder "testing" in this example in the current folder/directory you are in.

Creating a New File "touch"

There are number of ways to create a file. However, most of them open a text editor inside of terminal. For our purposes, we are going to shy away from that right away. These text editors (vim, nano, etc.) are a little advanced and I think it's best for beginners to continue using your favorite text editor of choice and retain the other features of terminal for now. So, with that said, the command "touch" will create a blank new file. It is used like so:

$ touch index.html

To create multiple files with one command you would run something like this:

$ touch index.html about.html

Copying Files "cp"

To copy a file you use the command "cp". Say we had a file named "index.html" and we wanted to make a copy of it and name it "about.html". That would like something like this:

$ cp index.html about.html

Notice the order, the first filename that comes directly after the "cp" command is the original and the second (about.html in this case) is the newly copied files filename.

Moving Files "mv"

Moving a file is very similar to copying one. The example should be self-explantory.

$ mv index.html about.html

Deleting Files (or Folders) "rm"

To delete a file you use the following syntax:

$ rm <file_name>

However, if you try to do the same with a directory/folder you will get an error. Let's say the name of the folder I was trying to delete was "project". You would get the following error using the above method:

rm: project: is a directory

To delete a folder you need override this with two different option flags "-r" and "-f". But before I give you the example, know that these flags mean that you are running a force removal. This means there will be no warning and it will delete the directory and all of it's contents. This means if you run this on the wrong directory, say your home folder or some other major folder on your computer you could cause serious damage. Be careful! With that said, here is the command:

$ rm -rf <folder_name>

After these quick tips you should be ready to dive into Node.js & NPM.

Pt. 1: Terminal Basics

Pt. 2: Node.js Install & Node Package Manager (NPM)


Jon Stuebe