Home Linux HTML/CSS PHP React VR Blog T-Shirt Shop PHP Fiddle

Basic Linux Commands I

Watch the video tutorial for this lesson:

Basic Linux Commands and Definitions:

If you find my tutorials helpful, please consider donating to support my free web development resources.

The more money I raise, the more content I can produce.

Thank you,
Commander Candy


Check out my blog:

Coding Commanders Blog

Linux/LampBasic Linux Commands

In this lesson, you will learn your first Linux commands! These are basic commands you will need to easily navigate through your new LAMP programming environment. If you do not have a Linux environment set up, visit: Setting up LAMP Lessons


Before we get into the commands, there are some basic definitions you should learn.

Information is stored in files. In Windows and OS X, anytime you 'save as' something (like a word document, image, video ect), you are creating a file. Once that file is created, you can make changes and 'save' to modify the file.

A directory is like a folder (in Windows and OS X). It is a way to organize your files. Basically it is a file created to store other files. Inside directories you can store files and other directories.

Home Directory:
Your home directory is where all your personal files are stored. You know you are in your home directory when you see '~' before the '$' on your command line.

Remember Linux, and other Unix family operating systems, are intended for multiple users. Think about a bussiness. There are probably multiple employees. Each employee is responsible for different tasks and will need access to certain directories.

Each employee will have their home directory. Employees can also be given permission to access additional directories.

What is root?
I think this concept can be confusing to beginners because there are multiple things that people refer to as 'root'.

Root User Also called root user or superuser, it is the user with access to everything. When we first set up Linux, you made an account name that is separate from root. However, you, the creator, by default still has access. Sometimes you just may have to give yourself permission.

You should never do your work as root. Use the username you set up. Root can do a lot of irreversible damage, including deleting your code or even your entire environment. Even experts stray from using root. It is certainly not advisable for a beginner.

Root User's Home Directory Also called /root or /root directory, this is the home directory for root user.

Root Directory Also called /, file tree root or root, this is the top directory in the directory tree. It is like the starting point for all files and directories.

File/Directory Location:
When using Linux or just about any programming language, you will have to specify the location of the file or directory that you are talking about.

If you do not know how to do this, look at HTML: File Path/Links.

Even though that lesson was writen for the HTML course, the location (file path) is writen using the same general rules.

The one thing that tutorial does NOT cover, that you will need to know, is going back to the root directory. If you want to go back to a directory that is located in the root directory you will put a '/' before the directory name.
Example: /var/www ← This means, go back to the root directory and look for a directory in root that is called var. Inside var is a directory called www. www is our diesired location.

IP address:
Or Internet Protocol address, is used to identify a computer (in our case a virtual computer). When the computer connects to the internet (or a private network), it is assigned an IP address.

In this course, we will run our code in the web browser, by typing the IP address into a web browser.


candy66@ubuntu:~$ ls

ls is used to see a list of directories and files within a directory. If you just type ' ls ', you will get a list of what is in your current directory. Your current directory is displayed before the '$' on the command line. To see inside a different directory you will type ls followed by the path to that directory → ls directory_name

List Example

$ ls projects

ls List the directories and files in a directoy
projects This is the directory we are looking into.

Change Directory

candy66@ubuntu:~$ cd

cd is used to change your directory. If you just type cd , you will go to your home directory. To go to a different directory, you will type cd followed by the path to the desired directory → cd directory_name/directory2

Change Directory Example

$ cd projects

cd Change directory
projects To the directory named projects
Note: projects must have been in a directory in our current directory.

Make Directory

candy66@ubuntu:~$ mkdir

mkdir is used to make a directory. If you want to create a directory inside your current directory, just type mkdir directory_name . If you want to make a directory inside a different directory, you can:

1) Change directories (cd desired_directory), then mkdir as shown above, because you will now be in the right directory (desired_directory)

2) Type mkdir followed by the appropriate path to the desired location
mkdir projects/games

Make Directory Example

$ mkdir projects/games

mkdir Make a directory
projects/games Call it games and put it in the projects directory.


candy66@ubuntu:~$ man

man is used to look up the user manual information about a command. This information includes the command's:

✶ Name/Definition
✶ Synopsis
✶ Description
✶ Options/Arguments

Manual Example

$ man ls

man Look up information about a command in the user's manual
ls This is the command we are looking up.

Interface Configuration (look up ip address)

candy66@ubuntu:~$ ifconfig

ifconfig is used to look up or modify the network's configuration. If you just type ifconfig with nothing after it, you will find useful information about your network. At first, you will probably mainly use it look up your ip address.

Interface Configuration (look up ip address) Example

$ ifconfig

ifconfig Look up information about the network, including your ip address


candy66@ubuntu:~$ shutdown

shutdown will power off your device in 60 seconds. We are running Ubuntu on a Virtual Machine (Oracle VirtualBox), so shutdown will power off the Ubuntu virtual disk image.

Shutdown Example

$ shutdown

shutdown Your virtual disk image (Ubuntu) will shutdown in 60 seconds

Shutdown Now

candy66@ubuntu:~$ shutdown now

If you don't want to wait 60 seconds, you can use shutdown now . It will power off immediately.

Shutdown Now Example

$ shutdown now

shutdown now Your virtual disk image (Ubuntu) will shut down immediately

Advanced Packaging Tool

candy66@ubuntu:~$ apt-get

apt-get commands are used to interact with APT (Advanced Packaging Tool). In other words, you will use it to do certain tasks relating to software packages. This includes:

✶ Installing new software
✶ Updating software
✶ Removing software

Advanced Packaging Tool Example

$ sudo apt-get install apache2

sudo Used for certain administrative tasks
apt-get we need to interact with software (installs & updates)
install We want to install
apache2 This is the name of the software we want to install


candy66@ubuntu:~$ rm

This is used to delete files and directories. rm file_name would delete a file called file_name. If you want to delete a directory, you have to put -r after rm, like this → rm -r directory_name
use rm -r directory very carefully! It will delete every directory inside that directory along with all of the sub-directories and files.

Remove Examples

$ rm quizGame.php
$ rm -r games

rm Delete
quizGame.php This is the file we want to delete
$ rm Delete
-r games games is the directory we want to delete.

Coding Commanders Storyline:

Coding Commanders Story

Watch the Coding Commanders LAMP Animation:

Coding Commanders: Episode 1

Color Selector



Follow Coding Commanders on:






Applied Assignment

Background: You just got a job doing web development for an HR department. Today is your first day and you recieved an e-mail with a list of tasks.
Assignment: If you have a Linux environment set up, preform these tasks in Linux. If you do not have a Linux environment set up, you can follow my tutorials to install Oracle VirtualBox, Ubuntu and Apach + MySQL + PHP.
Example Task: Create a directory named 'employees'. It should be located in your home directory.

Cisco Learning Network Store

Example Solution:

$ cd
$ mkdir employees

1) Look up the manual information for mkdir
2) Create a directory called 'employees' in your home directory.
3) Create 3 directories inside the 'employees directory': salary, contract, parttime
4) Inside the 'salary' directory, create 2 directories: management, nonmanagement
5) ✶Update: We will no longer have part-time employees. Delete the directory called 'parttime'.
6) List all the directories and sub-directories inside the employees directory.
7) Look up your ip address.