Learn › Linux Foundations › Linux and the shell

Chapter 1. Linux and the shell

Final test: Chapter 1, Linux and the shell. Twenty-five objectives on a real Debian 12 server: whoami, hostname in two forms, pwd, echo in five forms, date in five, uname in five, uptime in three, clear and history in two. Fifty minutes, graded from the commands you run.

Chapter 1. Linux and the shell

This chapter covers the following topics:

What you already know: nothing is assumed. This is the first chapter of the track, and every term is defined where it first appears.

Objectives

After this chapter you can:

Each exercise in this chapter is a practice terminal. It checks the one command it asks for, and nothing you type in it can break anything. After two wrong tries a See answer button appears. When you start the practice machine from the panel, the real server takes the place of these simulated terminals. The graded lab at the end of the chapter runs on a real Debian 12 server that prepares the chapter environment when you launch it. Follow the startup progress on screen. It records practice with the commands you run. Every command in this chapter reports a fact about you, the machine or the session, so every one of them works from any directory: it does not matter where the shell has left you standing.

Pre-check 1 of 5: what Linux is

Five questions before the material. A wrong answer costs nothing: the explanation states the fact and names the section that teaches it.

Pre-check 2 of 5: the shell

Pre-check 3 of 5: whoami

Pre-check 4 of 5: date

Pre-check 5 of 5: exit

1.1 What Linux is

A computer has hardware: a processor, memory, storage and network interfaces. It also needs software that tells those parts what to do. An operating system manages the machine and provides services that applications use.

The kernel is the central part of the operating system. It manages hardware and coordinates how programs use the processor, memory and devices. Linux is a kernel. It works with other software to form the system you use.

For this course, you also need a shell, tools such as ls and cp, and a way to install and update software. A distribution packages the Linux kernel with those tools into a usable system. Debian, Ubuntu, Red Hat Enterprise Linux, Fedora, Arch and Alpine are examples. Their default tools, package managers and update policies differ.

The Foundations practice server runs Debian 12, code-named bookworm. Many commands in this track also work on other distributions. Available tools, versions and options can differ, so check the local help when a command behaves differently. Alpine, for example, commonly uses smaller BusyBox versions of many tools.

Linux is used in web servers, cloud systems, supercomputers, Android devices and network equipment. These systems serve different purposes, but share the Linux kernel at their core. A useful historical example: all 500 systems in the November 2017 TOP500 list used the Linux operating-system family.

This track uses a server and the command line so you can practise the same tools used to inspect and manage real systems. You do not need to memorize market-share numbers or distribution names before starting.

1.2 From Unix to Linux

Linux inherits its design, its command names and most of its habits from Unix, an operating system started in 1969 at Bell Labs in New Jersey by Ken Thompson and Dennis Ritchie. Unix established the ideas this track is built on: a tree of directories, small programs that each do one job, and a text command line to combine them.

Ritchie created the C programming language in 1972. Unix was rewritten in C in 1973, which is why it could be moved to other kinds of computer instead of staying tied to one.

Unix belonged to AT&T, and by the 1980s a commercial license was expensive. In 1983 Richard Stallman announced the GNU project: a plan to write a complete Unix-like operating system that anyone could use, study, change and share. GNU stands for "GNU's Not Unix".

The GNU project developed tools that later became important parts of Linux distributions, including Bash, the Bourne Again Shell, first released in 1989. Today, GNU Coreutils packages many standard commands, including date, uname, whoami and pwd. The current Coreutils package brought earlier GNU tool collections together in 2002.

Linus Torvalds announced Linux in August 1991 and released its first code that September. In 1992, Linux adopted the GNU General Public License. People combined the kernel with GNU tools and other software to build usable systems. Distributions package and maintain those pieces together.

Debian was founded on 16 August 1993 by Ian Murdock. It is one of the oldest distributions still maintained.

One more name you will meet: POSIX, a family of standards describing common interfaces, shells and commands for Unix-like systems. Linux systems implement many of these interfaces, but support varies by system and tool.

POSIX defines common interfaces and commands, which helps many basic commands work across Unix-like systems. It does not make every installed tool or option identical. For example, uptime -p is available on this practice server, but may be absent on another system. Read that machine's manual or --help output before relying on an option.

Names such as ls, cd, pwd and cp have a long Unix history. Short names are quick to type, but can look unfamiliar at first. Learn each name with its purpose and an example; memorizing the dates is not the goal.

1.3 The terminal, the shell and the prompt

Three things are on your screen when you work on a Linux server, and they are often confused.

The terminal is the text interface you use. Older terminals were physical devices attached to another computer. Today, a terminal application displays text and sends keystrokes to the program running inside it. It can display a shell, an editor or another interactive program.

The shell reads and interprets command lines. In an interactive session it prints a prompt, accepts your input, then runs the command or built-in instruction you requested. Output appears in the terminal. When a foreground command finishes, the shell normally prints another prompt. This practice server uses Bash; other systems can use different shells.

The prompt tells you the shell is ready for input. Here is the simple example used in the lessons. Your live machine may use a different style or colours:

admin@server1:~$

In this example, admin is the account and server1 is the host. ~ represents the account's home directory. A $ is a common ordinary-user prompt marker; # is commonly used for root. Prompts are configurable, so the symbol alone does not prove which account you are using. Run whoami to check the account and pwd to check the directory. Chapter 7 covers root.

Type after the prompt; do not copy the prompt itself. In the simple commands here, the first word names a program or shell built-in. Words after it are arguments. Some arguments are options that change behaviour, often beginning with a hyphen, such as date -u. Others name input, such as a file. A leading hyphen does not always mean an option; each command defines what its arguments mean.

Type the command, then press Enter to submit the line. You can edit it before submitting. Command names are case-sensitive: this server has whoami, while Whoami does not name that command.

1.4 Who you are: whoami

whoami prints the user name of the account that is running the shell. It takes no arguments. Type it and press Enter:

prompt: admin@server1:~$ answer: whoami output: admin hint: Section 1.4. One word, no options: the command that prints the account name. It works from any directory.

One word back: admin, the same name the prompt shows before the @. whoami reports the account the shell is running as. Permission to read a file or run a command follows that account, not the person at the keyboard. After a switch to another account, which Chapter 7 covers, whoami reports the new one.

1.5 Which machine: hostname

Every Linux machine has a host name: the name the system knows itself by. It is stored in the file /etc/hostname, which Chapter 4 reads, and it appears in the prompt and in log lines. hostname prints it:

prompt: admin@server1:~$ answer: hostname output: server1 hint: Section 1.5. One word, no options: the command that prints the machine name. It works from any directory.

server1, the same name the prompt shows after the @. With several terminals open to several machines, this command is how you confirm which one you are about to type into.

1.5 hostname -I: the addresses

A machine on a network also has one or more IP addresses, the numbers other machines use to send it data. The -I option, a capital i, prints the addresses configured on this machine. It leaves out the loopback address, the one every machine uses to talk to itself:

prompt: admin@server1:~$ answer: hostname -I output: 172.237.130.132 2600:3c06::2000:79ff:fe1f:9fa1 hint: Section 1.5. The same host-name command with the capital option -I, the one that lists the addresses.

Your addresses will differ; every launch gets new ones. The first is an IPv4 address, four numbers separated by dots. The second is an IPv6 address, groups of hexadecimal digits separated by colons. Both name this one machine. Networking has its own track; here it is enough to know the command that reports them.

1.6 Where you stand: pwd

The shell is always standing in one directory. A directory is what other systems call a folder. pwd, print working directory, prints the full address of the one you are standing in:

prompt: admin@server1:~$ answer: pwd output: /home/admin hint: Section 1.6. Three letters, no options: the command that prints the directory you are standing in.

/home/admin is a path: the address of a directory, written from the top of the system. The first / is the root of the whole tree, home holds the personal directory of each ordinary account, and admin is yours. The prompt showed ~ for the same place. Chapter 2 is about moving through this tree.

1.7 Printing text: echo

echo prints its arguments back to the screen, one space apart, followed by a line break. Scripts use it to print messages. At the prompt it is how you see what the shell did to a line before the command saw it, which is what the next three exercises show.

Print the exact words Hello, world. No quotes are needed here, because there is only one space between the two words:

prompt: admin@server1:~$ answer: echo Hello, world ||| echo "Hello, world" output: Hello, world hint: Section 1.7. The command that prints text, then the exact words Hello, world.

The two words came back separated by one space, exactly as typed. The next two exercises show that the shell, not echo, decides how many spaces survive.

1.7 echo with quotes: spaces survive

Type the same greeting, Hello, then three spaces then world, and wrap the whole text in double quotes:

prompt: admin@server1:~$ answer: echo "Hello, world" ||| echo 'Hello, world' output: Hello, world hint: Section 1.7. The same text, Hello, then three spaces, then world, wrapped in double quotes so the shell keeps them.

Three spaces in, three spaces out. Inside double quotes the shell hands echo the whole text as a single argument, spaces and all.

1.7 echo without quotes: spaces collapse

Now the same text, Hello, then three spaces then world, with no quotes at all:

prompt: admin@server1:~$ answer: echo Hello, world output: Hello, world hint: Section 1.7. The same text, Hello, then three spaces, then world, with no quotes at all this time.

One space out. Before echo ran, the shell split the line into words wherever it found spaces, however many, and gave echo two arguments: Hello, and world. echo printed them one space apart. The rule to carry forward: the shell reads your line before the command sees it, and quotes tell the shell to leave a piece of it alone. Chapter 8 covers quoting in full.

1.7 echo -n: no line break

The -n option tells echo not to print the line break at the end. Print the single word Done with it:

prompt: admin@server1:~$ answer: echo -n Done ||| echo -n "Done" output: Done hint: Section 1.7. The echo command with the option -n, which holds back the line break, then the word Done.

The block above shows Done on a line of its own because the capture added the missing line break. On the machine the next prompt appears on the same line, right after Done, because nothing moved the cursor down. Scripts use -n to print a label and put the value after it on one line.

1.7 echo -e: one command, several lines

The -e option makes echo interpret escape sequences: two characters that stand for one special character. \n stands for a line break. Print one and two on two lines from one command: the text is "one\ntwo", in double quotes so the backslash reaches echo:

prompt: admin@server1:~$ answer: echo -e "one\ntwo" ||| echo -e 'one\ntwo' output: one two hint: Section 1.7. The echo command with the option -e, which reads escape sequences, then the text "one\ntwo" in double quotes.

Two lines from one command. Without -e, echo prints the backslash and the n as ordinary characters.

1.8 The clock: date

date prints the current date and time as the machine knows them. This server is set to UTC, Coordinated Universal Time, the reference time zone. UTC never shifts for daylight saving, so times written by machines in different countries can be compared directly. Many servers are set to it for that reason.

prompt: admin@server1:~$ answer: date output: Sun Sep 6 20:51:21 UTC 2026 hint: Section 1.8. The clock command on its own: no options and no format argument.

Your values differ; the shape is fixed: weekday, month, day of the month, time, time zone, year. The day of the month is printed in two columns, which is why a single-digit day has two spaces in front of it. This server keeps UTC, so the time shown is probably not the time on your wall clock.

1.8 date -u: UTC on purpose

On a machine set to a local time zone, -u prints UTC instead. On this server the two agree. -u is worth typing anyway when you compare times across machines, because its answer does not depend on how each machine is set:

prompt: admin@server1:~$ answer: date -u output: Sun Sep 6 20:51:21 UTC 2026 hint: Section 1.8. The clock command with the option -u, for Coordinated Universal Time.

The same instant as the exercise before it, and your own clock values differ from the ones shown. On a machine set to a local time zone the two forms differ by that zone offset, and -u is the one that can be lined up with a machine in another country.

1.8 date +%F: choose the format

An argument that starts with + is a format: a template of the parts you want. Inside it, a % followed by a letter stands for one part of the date. %F is the full date as year-month-day, the form that sorts correctly and that this track uses everywhere:

prompt: admin@server1:~$ answer: date +%F ||| date +%Y-%m-%d output: 2026-09-06 hint: Section 1.8. The clock command with the format argument +%F, the full year-month-day date.

%F is shorthand for %Y-%m-%d: four digit year, two digit month, two digit day. The date printed is the day you run it, so it differs from the one shown. Both spellings are accepted here.

1.8 date +%H:%M: the time only

Codes combine with any other characters you type. %H is the hour on a 24 hour clock and %M the minute; the colon between them is printed as is:

prompt: admin@server1:~$ answer: date +%H:%M ||| date "+%H:%M" ||| date +"%H:%M" output: 20:51 hint: Section 1.8. The clock command with the format argument +%H:%M: hour code, colon, minute code.

Only the two parts you asked for, in the order you asked for them, with the colon printed as typed. Your time differs from the one shown. Anything in the format that is not a % code is printed as it stands.

1.8 date +%A: the weekday

`%

Practice Chapter 1. Linux and the shell in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.