Accessing and using the Linux command line

1.4 ICT Skills and Working in Linux (Weight: 2)

📘Linux Essentials (LPI 010-160)


This section is very important for the exam. You must understand how to access the Linux command line, how it works, and how to use basic commands efficiently.

The Linux command line is one of the most powerful tools in an IT environment. System administrators, DevOps engineers, and support staff use it daily to manage servers, configure systems, troubleshoot issues, and automate tasks.


1. What is the Linux Command Line?

The command line is a text-based interface used to interact with the operating system.

Instead of clicking icons (GUI), you type commands to tell the system what to do.

The command line is also called:

  • Shell
  • Terminal
  • Console
  • Command-line interface (CLI)

In most Linux systems, the default shell is:

  • Bash (Bourne Again Shell)

2. What is a Shell?

A shell is a program that:

  • Takes commands from the user
  • Sends them to the Linux kernel
  • Displays the output

Think of it as a bridge between the user and the operating system.

Common Linux shells include:

  • Bash
  • sh
  • zsh
  • ksh

For the exam, you mainly need to understand Bash.


3. Accessing the Command Line

There are multiple ways to access the Linux command line.

3.1 Using a Terminal in a Graphical Desktop

If Linux has a graphical interface installed:

  • Open the Terminal application.
  • You will see a prompt like:
username@hostname:~$

This means:

  • username → current user
  • hostname → system name
  • ~ → home directory
  • $ → normal user
  • # → root user

3.2 Switching to a Virtual Console (TTY)

Linux provides virtual text terminals.

You can switch using:

Ctrl + Alt + F1–F6

To return to GUI:

Ctrl + Alt + F7 (or F1 depending on distro)

These are often used in:

  • Server environments
  • Troubleshooting GUI failures

3.3 Remote Access Using SSH

In IT environments, systems are often managed remotely.

The most common method is SSH (Secure Shell).

To connect:

ssh username@remote_host

SSH allows secure remote login to Linux servers.

Common SSH client tools:

  • Built-in ssh command
  • PuTTY (Windows)
  • Terminal (macOS/Linux)

For the exam:

  • Understand SSH is used for secure remote command-line access.
  • It encrypts communication.

4. Understanding the Command Prompt

Example prompt:

student@server01:~$

Meaning:

PartMeaning
studentLogged-in user
server01Hostname
~Home directory
$Normal user

If you see:

root@server01:~#

# means you are root (superuser).


5. Basic Command Structure

A Linux command follows this structure:

command [options] [arguments]

Example:

ls -l /home
  • ls → command
  • -l → option (long format)
  • /home → argument (target directory)

6. Getting Help in Linux

Very important for the exam.

6.1 Using man

Manual pages:

man ls
  • Shows full documentation.
  • Press q to exit.

6.2 Using --help

Most commands support:

ls --help
  • Shows short help information.

6.3 Using info

info ls

Another documentation system (less common for beginners).


7. Navigating the File System

Understanding directories is essential.

7.1 Current Directory

Check where you are:

pwd

(Print Working Directory)


7.2 Listing Files

ls

Common options:

ls -l     # detailed list
ls -a # show hidden files
ls -lh # human-readable sizes

Hidden files start with .


7.3 Changing Directory

cd /path/to/directory

Special shortcuts:

CommandMeaning
cdGo to home directory
cd ..Go up one level
cd –Go to previous directory
cd ~Go to home

8. Working with Files and Directories

8.1 Create Files

touch filename

8.2 Create Directories

mkdir directory_name

8.3 Remove Files

rm filename

Remove directory:

rm -r directory

Be careful — rm permanently deletes.


8.4 Copy Files

cp source destination

8.5 Move or Rename Files

mv oldname newname

9. Viewing File Contents

9.1 Display File

cat file.txt

9.2 Page-by-Page Viewing

less file.txt
  • Scroll up/down
  • Press q to quit

Common in log analysis in IT systems.


10. Understanding Absolute and Relative Paths

Absolute Path

Starts from root:

/home/student/file.txt

Relative Path

Based on current location:

documents/file.txt

Root directory is:

/

11. Command History

Linux saves previously typed commands.

View History

history

Re-run Last Command

!!

Search History

Press:

Ctrl + r

Very useful for system administrators.


12. Tab Completion

Press:

Tab

Linux auto-completes:

  • Commands
  • File names
  • Directories

This increases speed and reduces typing errors.


13. Command Line Editing Shortcuts

Important for efficiency:

ShortcutFunction
Ctrl + CStop running command
Ctrl + LClear screen
Ctrl + DLogout
Ctrl + AMove cursor to start
Ctrl + EMove cursor to end

These are very useful in server management.


14. Running Commands as Root (Superuser)

Some commands require administrative privileges.

Use:

sudo command

Example:

sudo apt update

sudo allows a permitted user to execute a command as root.

In enterprise systems, this is used for:

  • Installing software
  • Managing services
  • Changing system settings

15. Understanding Exit Status

After a command runs, Linux stores its exit status.

Check with:

echo $?
  • 0 → Success
  • Non-zero → Error

Important for scripting and troubleshooting.


16. Command Substitution

Use output of one command inside another:

$(command)

Example:

echo $(date)

This is useful in automation and scripting.


17. Redirection (Basic Concept)

Linux allows redirecting input/output.

Redirect Output to File

command > file.txt

Append:

command >> file.txt

Redirect Errors

command 2> error.txt

Pipe Output

command1 | command2

Example:

ls -l | less

Pipes are heavily used in server management and log processing.


18. Environment Variables

View variables:

env

Common variable:

echo $PATH

PATH defines where Linux searches for commands.

If a command is not in PATH, it must be run using full path:

/bin/ls

19. Logging Out

To exit shell:

exit

or

Ctrl + D

20. Why the Command Line is Important in IT

In professional IT environments:

  • Many servers do not have graphical interfaces.
  • Cloud systems are managed via SSH.
  • Automation requires command-line skills.
  • Troubleshooting often requires CLI tools.
  • Scripts are written in shell.

Understanding the command line is essential for:

  • Linux administrators
  • DevOps engineers
  • Security analysts
  • Cloud engineers

Exam Summary – What You Must Know

For the Linux Essentials exam, make sure you understand:

✔ What the shell is
✔ How to access the command line (Terminal, TTY, SSH)
✔ Command structure (command + options + arguments)
✔ Basic file navigation commands (pwd, ls, cd)
✔ File management commands (cp, mv, rm, mkdir, touch)
✔ Viewing file contents (cat, less)
✔ Absolute vs relative paths
✔ Using man and –help
✔ Command history and tab completion
✔ Redirection and pipes
✔ sudo and root user
✔ Environment variables (especially PATH)
✔ Exit status and basic shell behavior

Buy Me a Coffee