Linux Administration Lesson 4 – Basic Linux Commands | Dataplexa
Section I — Linux Fundamentals

Basic Linux Commands

In this lesson

Terminal and shell basics Navigation commands File and directory operations Viewing file content Command structure and flags

Linux commands are instructions typed into a shell that tell the operating system to perform specific tasks — navigating directories, creating files, reading content, or managing processes. Unlike graphical interfaces, the command line gives administrators precise, scriptable, and repeatable control over every aspect of a Linux system. Mastery of basic commands is the single most important practical skill in Linux administration.

The Terminal and the Shell

Two terms that beginners often confuse are terminal and shell. The terminal is the window you type into — it is purely a display program. The shell is the program running inside that window that interprets your commands and communicates with the kernel.

Terminal (Display Window) $ ls -la total 48 drwxr-xr-x ... input Shell (Bash) (Command Interpreter) Parses command Expands variables Calls system calls syscall Kernel (OS Core) Reads filesystem Returns result to shell

Fig 1 — Your typed command travels from terminal to shell to kernel and back

The default shell on most Linux distributions is Bash. The prompt shows your username, hostname, and current directory:

alice@webserver:~$

The $ means regular user; # means root.

Analogy: The terminal is a telephone handset. The shell is the person on the other end who understands your language. The kernel is the organisation that actually carries out the request.

Command Structure

Every Linux command follows the same pattern: command → options → arguments.

ls -l -a /home/alice COMMAND the program OPTIONS flags / switches ARGUMENT target / input

Fig 2 — Anatomy of a Linux command

Command Components
Command ls, cd, cp The program or built-in to execute. Always comes first.
Options / Flags -l, -a, --all Modify behaviour. Short flags use -, long flags use --. Can be combined: -la
Arguments /home/alice, file.txt The target the command acts on. Optional for some commands.

Navigation Commands

Navigation is the foundation of all terminal work. These three commands must become muscle memory.

pwd — Print Working Directory

Outputs the full absolute path of your current directory. Run this first on any unfamiliar server.

pwd

What just happened? The shell asked the kernel for the current working directory and printed its absolute path. You are in /home/alice.

cd — Change Directory

Moves you into a different directory. Accepts both absolute and relative paths.

# Move to an absolute path
cd /etc/ssh

# Move up one level
cd ..

# Move to your home directory
cd ~

# Move to the previous directory
cd -

ls — List Directory Contents

Lists files and directories. Its flags are among the most commonly used in Linux.

# Basic listing
ls

# Long format — shows permissions, owner, size, date
ls -l

# Show hidden files (names starting with .)
ls -a

# Long format + hidden files combined
ls -la

# Human-readable file sizes (KB, MB, GB)
ls -lh

# List a specific directory without entering it
ls -la /etc

What just happened? The -la flags combined long format and hidden files. Each line shows permissions, link count, owner, group, size in bytes, modification date, and filename. Files beginning with . are hidden configuration files.

File and Directory Operations

Creating, copying, moving, and removing files and directories are daily tasks. Several of these commands are irreversible.

File Operation Commands
Command Purpose Example
touch Create empty file or update timestamp touch notes.txt
mkdir Create a new directory mkdir -p /opt/app/logs
cp Copy file or directory cp -r /etc/nginx /backup/
mv Move or rename file/directory mv old.txt new.txt
rm Remove file or directory rm -rf /tmp/oldlogs
rmdir Remove an empty directory rmdir empty_folder
# Create nested directories in one command
mkdir -p /opt/myapp/config/ssl

# Copy a directory recursively (-r required for directories)
cp -r /etc/nginx /backup/nginx-backup

# Rename a file using mv
mv server.log server.log.bak

# Move a file to a different directory
mv server.log.bak /var/log/archive/

Viewing File Content

Reading configuration files, logs, and scripts without opening an editor is a core daily skill.

cat
Concatenate and print

Prints the entire file at once. Best for short files. Avoid on large files — the output floods the terminal.

less
Scrollable pager

Opens a file in a scrollable viewer. Use arrow keys to navigate. Press q to quit. The go-to tool for reading large log files.

head
First N lines of a file

Prints the first 10 lines by default. Use -n to specify a count.

tail
Last N lines of a file

Prints the last 10 lines by default. The -f flag follows the file in real time — essential for watching live log output.

grep
Search for a pattern in a file

Searches file content and prints matching lines. One of the most powerful and frequently used commands in Linux.

# Print entire file
cat /etc/hostname

# Scroll through a large file
less /var/log/syslog

# First 20 lines of a file
head -n 20 /etc/passwd

# Last 50 lines of a log file
tail -n 50 /var/log/auth.log

# Follow a log file in real time (Ctrl+C to stop)
tail -f /var/log/syslog

# Search for "error" in a log file (case-insensitive)
grep -i "error" /var/log/syslog

# Show line numbers with matches
grep -n "sshd" /var/log/auth.log

What just happened? tail -f opened the syslog and continued streaming new lines as they were written. Press Ctrl+C to stop following.

Essential Utility Commands

A small set of utility commands appears constantly in day-to-day administration work.

echo

Prints text or variable values to the terminal. Fundamental in scripts and for quick output testing.

echo "Hello, $USER"
whoami

Prints the current logged-in username. Critical for verifying whether you are root before running privileged commands.

whoami
man

Opens the manual page for any command. The most complete reference available. Press q to exit.

man ls
clear

Clears the terminal screen. Keyboard shortcut: Ctrl+L.

clear
history

Lists previously run commands. Use !N to re-run command N, or the up arrow to cycle.

history | tail -20
which

Shows the full path of a command binary. Confirms which version is executed when multiple are installed.

which python3

rm -rf Has No Undo

Linux has no Recycle Bin. Running rm -rf permanently deletes with no recovery option. Always double-check your path with pwd before running any rm command on a production server.

Lesson Checklist

I can distinguish between a terminal and a shell and explain the role of each
I can navigate the filesystem using pwd, cd, and ls with appropriate flags
I can create, copy, move, and delete files and directories safely
I can view file content with cat, less, head, tail -f, and grep
I understand the anatomy of a Linux command — command, options, and arguments

Teacher's Note

The fastest way to build command fluency is a live terminal session. Spin up an Ubuntu or Rocky Linux VM and spend 20 minutes navigating directories, creating files, and reading logs. Typing the commands yourself is irreplaceable — reading alone is not sufficient.

Practice Questions

1. You connect to a production server via SSH and need to immediately confirm your current directory, the username you are logged in as, and list all files including hidden ones. Write the three commands in order.

2. A web application is producing errors. Describe the commands you would use to (a) watch the application log file in real time and (b) search that same log file for lines containing the word "CRITICAL".

3. Explain the difference between cp -r and mv when applied to a directory. Give a scenario where you would use each.

Lesson Quiz

1. A terminal prompt ending with # instead of $ indicates which of the following?

2. Which command is best suited for monitoring a log file as new entries are written in real time?

3. The command mkdir -p /opt/app/config differs from mkdir /opt/app/config in which way?

Up Next

Lesson 5 — Working with Files and Directories

Wildcards, find, redirection, pipes, and advanced file manipulation techniques