CodeGym /Courses /Docker SELF /Command Line Basics (CLI): Command Structure, Working wit...

Command Line Basics (CLI): Command Structure, Working with the Terminal

Docker SELF
Level 1 , Lesson 4
Available

1. Getting to Know the Linux Command Line

Why the Command Line?

Before we dive in, let's answer the main question: why even bother with the command line if Linux has all these nice graphical interfaces? The command line (Command Line Interface, CLI) is a tool for pros, sysadmins, and programmers. With the CLI, you can get stuff done faster, automate boring tasks, and even do some behind-the-scenes magic without ever taking your hands off the keyboard. CLI is basically a superpower in the Linux world that lets you be super efficient.

Terminals, Shells, and the CLI

Before you type your first command, let's break down what's behind the magic of the terminal.

1. Terminal

A terminal is a program that gives you access to the command line. It lets you interact with your operating system using text. In Linux, here are some popular terminals:

  • GNOME Terminal (on GNOME).
  • Konsole (on KDE).
  • xterm (legendary, but kinda old school).
  • Windows Terminal for WSL

2. Shell

A shell is software that interprets your commands and passes them to the operating system. In Linux, the most popular shell is Bash (Bourne Again Shell). Alternatives:

  • Zsh: an advanced shell for customization fans.
  • Sh: classic Unix shell (minimalist).

We'll start with Bash since that's the standard.


2. Command Structure

Commands in the CLI have a strict format, and understanding it is key to success.

Basic Command Format

Every command has three parts:

[Command] [Options] [Arguments]
  • Command: what you're asking the system to do. For example, ls (show a list of files).
  • Options (or flags): tweak how the command works. For example, -l (detailed list for ls).
  • Arguments: extra info you give the command, like a file or folder path.

Example:

ls -l /home

Here:

  • ls — the command;
  • -l — option for showing a detailed list;
  • /home — argument (the folder we want to look at).

3. Navigation and Basic CLI Commands

Let's start with the simplest commands that show how to interact with the system.

1. Who am I? Where am I?

  • whoami: shows the current user.

    $ whoami
    student
    
  • pwd (print working directory): shows your current directory.

    $ pwd
    /home/student
    
Important!

In most Unix/Linux shells, the $ symbol is used as the prompt in the terminal. It means the system is ready for your command. The $ symbol separates the commands you need to type from their output.

2. Let's Look Around

  • ls (list): shows what's in your current directory.

      $ ls
      Documents  Downloads  Music
    

    Useful options:

    • -l: detailed info about files and folders.
    • -a: show hidden files.

Example:

ls -la

3. Moving Between Folders

  • cd (change directory): lets you move between directories.
    $ cd /home
    $ pwd
    /home
    

4. Terminal Hotkeys

The command line has a bunch of handy keyboard shortcuts:

  • Ctrl+C: stops the current command.
  • Ctrl+D: ends the current session.
  • Tab: autocomplete for files or folders. Super useful—use it a lot.
  • Arrow Up/Down: scroll through your recent commands.

Pro tip: if you want to feel like a hacker, hitting Ctrl+C while looking away is the perfect move.


5. Simple Command Examples: Let's Get Hands-On!

Let's make a simple practical task and solve it using the CLI.

Task:

  1. Find out the current user.
  2. Go to your home directory.
  3. See what's in there.
  4. Create a folder called test_folder.
  5. Check if the folder showed up.

Solution:


# Find out the current user
whoami

# Go to the home directory
cd ~

# See what's in the directory
ls

# Create a folder
mkdir test_folder

# Check if it's there
ls -l

Step-by-step Explanation:

  1. With whoami we checked which user we're working as.
  2. With cd ~ we moved to the home directory. The ~ symbol always points to the current user's home folder.
  3. The ls command showed the directory contents before and after creating the folder.

6. Common Mistakes and How to Avoid Them

Working with the command line always comes with mistakes, especially at first. Here are some common situations:

  • Spaces in file/folder names. If you're working with names that have spaces, always put them in quotes. For example:

    mkdir "My Folder"
    
  • Wrong paths. If you see No such file or directory, it means you gave a path that doesn't exist.

    cd /unknown/path
    
  • Typos in commands. The terminal doesn't forgive mistakes: lss instead of ls is a different command (or maybe doesn't exist at all).


7. Why Bother With All This?

CLI is a powerful tool for managing any system. It's used everywhere: from setting up servers to writing automation scripts. In interviews, you're often asked about commands for doing stuff in the terminal, so the knowledge you're getting now will definitely come in handy.

Plus, CLI will help you get the hang of version control systems like git, develop server-side apps, and write scripts for automation. It all starts with understanding the basics: command structure, moving between folders, and basic keyboard shortcuts.

A Little Practice

Try this task:

  1. Find out the current date.
  2. Create a folder called logs.
  3. Inside it, create a file log.txt with the current date written in it.
Example Solution

# Find out the current date
date

# Create the logs folder
mkdir logs

# Write the date to log.txt
date > logs/log.txt

# Check the file contents
cat logs/log.txt

Now you're ready for the next level—working with the file system and its contents!

8. What is the CodeGym Plugin and Why Do You Need It?

You can solve tasks on the website and in JetBrains IDEs with the CodeGym plugin and Shell Script (usually Shell Script is already installed).

If you don't have an IDE installed, we recommend installing IntelliJ IDEA Community Edition.

  1. Instructions on how to install IntelliJ IDEA.
  2. How to create your first project.

You can download the CodeGym plugin from the Jetbrains marketplace, right inside your IDE.

  1. Go to "Settings", Windows/Linux File - Settings, MacOS IntelliJ IDEA - Preferences. If you don't see the settings section, open any project or create a new one.

  2. In the window that pops up, pick Plugins from the side menu and open the Marketplace tab. In the search bar, type codegym

  3. Pick the plugin and hit the Install button.
  4. Restart IntelliJ IDEA to start using the plugin.
  5. You'll see a slightly changed interface and a Sign In button on the top horizontal panel.
  6. When you click it, a window will pop up for you to log into your account, where you need to enter your secret key. Reminder: you can find your secret key in “Settings” → “Security and Login”.

  7. To open a new task, click Tasks on the left vertical panel, then click the task card on the left sidebar, and in the popup window hit Open:

  8. Now you'll see a window with two tabs. One is the task description, the other is for your code. And you'll get a message from shellcheck to check your shell scripts—just agree.
  9. Now type your solution and hit Validate to send your task for review or run it locally.

The plugin is installed! Now you can solve tasks.

Syncing Tasks: Website ↔ Plugin

The list of tasks and their statuses updates automatically every five minutes or after you send any task for review (CodeGym server).

So if you solved a task on the website, it'll also show up as solved in the plugin. If you want to update the task statuses right now, click your avatar (top right), and in the dropdown menu pick Sync Tasks:

Beginner Mode in the Plugin

This is a simplified version for users who have little or no experience with IntelliJ IDEA or other IDEs. Some IntelliJ IDEA features are hidden in this mode. To turn off this mode, click your avatar (top right), and in the dropdown menu pick Settings:

How to Hide the Plugin Navigation Panel in PRO Mode

Click Settings (⚙️) and uncheck "Show plugin navigation panel":

1
Task
Docker SELF, level 1, lesson 4
Locked
Determining the current user
Determining the current user
1
Task
Docker SELF, level 1, lesson 4
Locked
Determining the current directory
Determining the current directory
1
Task
Docker SELF, level 1, lesson 4
Locked
Creating and Navigating
Creating and Navigating
1
Task
Docker SELF, level 1, lesson 4
Locked
Creating and Navigating
Creating and Navigating
Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Karas Level 1, Tampa, United States
17 January 2026
CodeGym you did it again. Hands on exercises! you guys are amazing!