Chapter 3

Basic Linux Commands

Linux is very powerful because of its command-line interface. In this section, you'll learn the most important basic commands you will use every day.

Introduction

The terminal is where you type commands. The shell (like Bash or Zsh) is the program that reads your commands and runs them.

Terminal and shell

Terminal and shell

Navigation commands

These commands help you move around the Linux file system:

Working with files and directories

Use these commands to create, view, and remove files or folders:

Viewing file content

These commands help you read what's inside files:

Getting help

Linux has built-in help so you can learn commands directly in the terminal:

Tip: Practice is the best way to learn. Create a test folder in your home directory and play with these commands so you don't break anything important.

Common basic commands summary

Memorize these to feel at home in the terminal:

CommandWhat it does
pwdShow current directory.
lsList files and folders.
cdChange directory.
mkdirCreate a new directory.
rmRemove files (and with -r, directories).
cpCopy files or directories.
mvMove or rename files or directories.
cat / lessView file contents.

Practice questions

Question 1

Open a terminal and write down the exact commands you used to create a folder called linux_practice and then create an empty file notes.txt inside it.

Hint: Think about mkdir, cd, and touch.

Question 2

Which 3 commands do you think you will use the most in your daily Linux work, and why?

Hint: For example ls, cd, cat, less, etc. Explain your choice.

Quiz

Test your understanding. Click an answer to see if it's correct.

1. Which command shows the current directory you are in?

  • ls
  • cd
  • pwd
  • mkdir

pwd means "print working directory" and shows your current path.

2. What is the safest way to go back to your home directory?

  • cd /
  • cd ~
  • rm -r ~
  • cd ..

~ represents your home directory in most shells.

3. Which command will create a new directory called projects?

  • newdir projects
  • mkdir projects
  • touch projects
  • ls projects

Use mkdir (make directory).

4. You want to see the content of a small text file named readme.txt. Which command is most suitable?

  • rm readme.txt
  • ls readme.txt
  • cat readme.txt
  • pwd readme.txt

cat will print the content of the file to your terminal.

5. Which of these commands is dangerous if used carelessly?

  • ls
  • pwd
  • rm -r /
  • cd ..

rm -r / could delete important files; never run destructive commands you don't fully understand.

Nice work! You've learned the essential commands. Next, let's understand how the Linux file system is organized.