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.
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
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.
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.
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.
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
$ ls projects
List the directories and files in a directoy
➼ projects This is the directory we are looking into.
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
$ cd projects
➼ cd Change directory
➼ projects To the directory named projects
Note: projects must have been in a directory in our current directory.
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
$ mkdir projects/games
➼ mkdir Make a directory
➼ projects/games Call it games and put it in the projects directory.
man is used to
look up the user manual information about a command.
This information includes the command's:
$ man ls
➼ man Look up
information about a command in the user's manual
➼ ls This is the command we are looking up.
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.
➼ ifconfig Look up
information about the network, including your ip address
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 Your virtual disk image (Ubuntu) will shutdown in 60 seconds
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
➼ shutdown now Your
virtual disk image (Ubuntu) will shut down immediately
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
$ sudo apt-get install apache2
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
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.
$ 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.
$ mkdir employees