Lesson 3 - Working in the Terminal

Progress 0%

Interactive Terminal Sim:

Becoming Faster at the Terminal

So far you've learnt a handful of commands, but real linux users rarely type every command out from scratch or work throgh problems alone. The terminal has a large array of built in tools to help you work faster, get help when you're stuck and cancel things that go wrong.

In this lesson, you'll learn how to reuse old commands, read a commands manual, and stop a command that is running. These are all essential skills for working in the linux terminal.

Reusing Old Commands with History

Every command you type is remembered by the shell. your past commands with:

history

This prints a numbered list of everything you have run in this session. You can also press the up and down arrow keys to cycle back through previous commands instead of retyping them.


Try using a few commands like pwd and ls and then use the up and down arrows to cycle through them. Then run history to see them listed.

Getting help with Man

The command man is short for "manual", and it is one of the most helpful commands in the terminal. Almost every command has a manual page that explains what it does, how to use it, and what options it accepts.

You can view a command's manual page by typing man followed by the command you want to learn about. Try it on a few commands you've learnt so far, for example, try typing:

man ls

Play around with the man command, as it is very helpful for when, and you will, forget how to use a command.

Searching Text with grep

The grep command is used to search for text in files. It can be used to find specific words or phrases in a file, and it can also be used to search through multiple files at once.

grep Linux Documents/notes.txt filename

This prints every line in the file notes.txt that contains the word "Linux". Add the -i flag to ignore uppercase and lowercase differences.

grep -i Linux Documents/notes.txt

grep is one of the most-used tools on Linux, especially for digging through large log files to find errors.

An absolute path starts at the root directory / and gives the complete location of something.

/home/student/Documents

This path always refers to the same location, regardless of which directory you are currently in.

Chaining and Cancelling Commands

You can run two commands one after the other with the && operator. The second command will only run if the first one succeeds.

pwd && ls

This is useful for building small sequences of commands such as moving into a directory and then listing its contents. You can use && for any amount of commands, for example:

cd Documents && ls && grep Linux notes.txt

Sometimes a command takes too long, gets stuck or you simply want to stop it. On a real terminal, you can stop any command by pressing Ctrl+C this sends an interrupt signal and cancels whatever is currently running, handing control back to you. Try pressing Ctrl+C in the terminal sim now while it's idle, it will simply return you to a fresh prompt.


With history, man, grep, && and Ctrl+C in your toolkit, you're ready to work through the terminal a lot more efficiently.