ED 101: Essential Linux (15 pts + 10 pts extra)

What You Need for This Project


To practice basic Linux commands and understand how to efficiently improve your Linux command-line skills.

Structure of this Project

Work through the commands and explanations below. After that, there are challenges to solve, without instructions. You can solve the challenges using the techniques explained below.

1. ls

This is the most important command of all. It shows you the files and folders in the working directory, so you can see where you are and what's going on.

Execute this command (lowercase LS):

This command shows files and directories in the current working directory, as shown below.

"ls" by itself isn't very useful, because it doesn't tell you much about the items. The next command is far more helpful.

Execute this command (lowercase LS -L):

ls -l
This "long list" tells you a lot more information, as shown below.

The first character in each line is "d" for directories, or "-" for files. Towards the right, it shows the size of the file or directory in bytes and the date it was last modified, with the name at the far right.

My working directory contains only directories, no files.

2. Getting Help

There are three ways of getting help that I recommend: --help, Google, and man.

If you want a brief summary of command options, execute the command followed by "--help". Execute this command:

ls --help
A "brief" help page appear, as shown below.

Even that "brief" page contains far more information than I usually want to see. Most of those arguments are obscure and I never use them. My main source of help is actually Google.

Ooen a Web browser and go to google.com. Then search for

linux ls examples

You get a lot of really useful information, as shown below.

Go to this page and skim through the options to see some more ways to use "ls".


Execute this command:

man ls
This shows you a long, technical, and very confusing manual page about "ls" as shown below. This type of help is almost completely useless for beginners--it provides far too much information.

Press q to exit man.

3. Editing Files

Execute this command:
nano file1
Nano opens, as shown below. Nano is a very simple text editor, like Notepad without the mouse. Type in some text.

Notice the bottom of the nano screen--the available commands are shown here in a shorthand form.

Notice the lower left entry "^X Exit". This means that you can exit nano by pressing Ctrl+X. Press it now.

The next screen asks if you want to save the file. The bottom shows your options: Y, N, or Ctrl+C. Type Y.

At this screen, you can press Enter to save the file, or edit the name before saving it. Unfortunately, the list of commands at the bottom don't tell you either of those facts.

Press Enter.

To see what you've done, execute this command:

ls -l
There's now an entry for "file1", as shown below.

4. Changing Directories

Execute this command, which stands for "print working directory":
The result is "/root", as shown below. That's the directory we've been using.

Execute these commands. The first one makes a new directory, and the second one lists out the contents of the current working directory.

mkdir proj0
ls -l
Now there's a directory named "proj0" in the working directory, as shown below.

Execute these commands. The first one moves file1 into the "proj0" directory, and the second one lists out the contents of the current working directory.

mv file1 proj0
ls -l
"file1" no longer appears in the list, as shown below.

Execute these commands. The first one moves into the "proj0" directory, the second one shows the new working directory, and and the third one lists out the contents of the new current working directory.

cd proj0
ls -l
This directory contains only one file, as shown below.

5. Output Redirection

Execute these commands. The first one prints the current date. The second one sends the date to a file named "file2". The third one shows the long list of the current working directory.
date > file2
ls -l
There's now a file named "file2", as shown below.

Execute this command to open "file2" in nano.

nano file2
The file contains the date, as shown below.

Press Ctrl+X to exit nano.

6. Displaying and Searching File Contents

To see the contents of a file, use cat.

Execute this command to display the contents of file1.

cat file1
The contents appear, as shown below.

To search for a string in a file, use grep.

Execute these commands to display the lines in the file1 containing the string ab, and the lines in the file1 containing the string ab,

grep ab file1
grep a file1
The matching lines appear, as shown below.

You can use the -r switch to search directories and subdirectories recursively.

Execute this command find all lines containing a in the current directory and all subdirectories.

Don't omit the period at the end--that's called "dot" and it denotes the current working directory.

grep a -r .
All matching lines in all files are found, as shown below.

7. Shell Scripting

Execute this command to open nano and start creating a file named "count".
nano count
Enter this text, as shown below.

for i in 1 2 3
echo $i

Press Ctrl+X, Y, Enter to save the file.

This script should count from one to three. Execute this command to run the script:

An error message appears, saying "Permission denied", as shown below.

To see why this happened, execute this command:

ls -l
Notice the beginning of the line containing "count" as shown below.

This line starts with "-", indicating that this is a file, not a directory. The next 9 letters are the permission string, using these letters:

The current permission string doesn't contain any "x" characters, so no one has permission to execute it.

Execute these commands to give execute permission to the "count" file for all users, and to see the new permissions:

chmod a+x count
ls -l
As shown below, the file now has three "x" permissions, and the name turns green, to indicate that this is an executable file.

Execute this command to run the "count" script:

As shown below, the script runs, counting from 1 to 3.

8. Networking

Execute this command to see what network adapters you have and your IP address:
As shown below, there are two adapters:

eth0 has an IP address (labelled "inet") and goes to the Internet.

lo is the loopback address and doesn't go anywhere. Your computer uses that address to talk to itself, which is useless for normal Web browsing.

Execute this command test your Internet connection:

ping google.com
As shown below, you should see "reply" messages, indicating that your Internet connection is working.

Press Ctrl+C to stop the pings.

If you move your computer to a new network, it might lose connectivity because it's still using an old IP address.

To fix that problem, execute this command:

dhclient -v eth0
As shown below, your computer sends out DHCPDISCOVER messages, and gets an IP address from the router.

ED 101.1: Using Directories (5 pts)

Execute these commands:
cd /tmp
mkdir apple
mkdir baker
cd baker
mkdir charlie
Find your current working directory. That's the flag.

ED 101.2: Network Test (10 pts)

The file /tmp/pinger contains these two lines:

However, the script will not run:

What command will fix this problem? That command is the flag.

ED 101.3: Network Problem (10 pts extra)

This machine can't ping google.

What command should be executed to fix the problem? 15 pts + 10 pts extra

Posted 6-13-18
Challenges 3 and 4 added 6-14-18
In 6. "cat count" removed 11-5-19
Video added 3-15-23