Command line for a newbie

Basics of command line explained. Functionality you should become familiar with.

What development can you do with the command line

The command line interface has become useful for scaffolding development projects in less time and with less effort.

With tools like git offering a simple but powerful version control interface it is becoming very important to add the command line to your toolbelt.

There are multiple online package libraries from which to download and install using the command line.

For php there is packagist.

For python there is pip.

For front end packages like angular or jquery and much more, there is npm.

The basics

So here’s a quick overview of the beginner stuff.

Change your location

When you open your command line tool, you will be in a particular folder on your computer. For windows you may be in C:\ and for ubuntu you may be in ~/

To change your location you can use command cd

cd [path]

Windows

Eg: cd C:/Projects/

Linux

Eg: cd ~/Projects

View files in current directory

As you move around the different folders on your computer you will want to see what other folders or files are within the folder you change to.

For Linux you will use the command ls:

ls

For Windows you will use the command dir:

dir

These will return a list of files and folders in the current folder.

You can combine this with a folder path in order to see a list of files and folders in a folder you are not currently in.

Linux:

ls [folder location]
Eg: ls /var/log

Windows:

dir /a [folder location]
Eg: dir /a C:/

Creating directories

Create a directory in the current location.

mkdir

If you want to create a directory in a different location you will need to use cd to go there.

Create a file

Ubuntu:

touch [filename]
eg touch index.html

Windows:

There are multiple ways to create a file in windows. You will just need to select the approach that works for you. Below are two of the various ways to create files on windows.

echo 2> [filename]

fc >> [filename]

Alternatively you can use notepad:

notepad [filename]

This will open up notpad which will then ask you if you would like to create a file named [filename]

Rename a file

ren

ren [current filename] [new filename]

Delete files

For Linux use rm

rem [filename]

For Windows use

DEL [filename]

Keep learning

This is only the tip of the iceberg. The command line is a very powerful interface and can save you a lot of time.