Operations 21 min read

Master Linux Command Line: Essential Commands and Real‑World Examples

This comprehensive guide introduces Linux fundamentals, explains the relationship between Linux and Unix, describes kernel, shell, and application layers, compares network modes, and provides detailed usage examples for common commands such as init, man, pwd, ls, cd, mkdir, rmdir, touch, cp, rm, mv, cat, grep, tar, zip, and date, helping readers efficiently manage Linux systems.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Command Line: Essential Commands and Real‑World Examples

Linux Common Operations Commands and Examples

1. Linux Basics

1.1 Introduction to Linux

Pronunciation: /li’nʌks/ or /li:nɛks/.

Linux is a free, open‑source, secure, efficient, and stable operating system widely used in enterprise environments.

Major distributions include Red Hat Linux, Debian Linux, Ubuntu Linux, Suse Linux, etc.

Linux was created by Linus Torvalds while studying at the University of Helsinki.

1.2 Relationship between Linux and Unix

Unix was invented by Ken Thompson and Dennis Ritchie, originating from the Multics project.

Linux is a Unix‑like system; it mimics Unix’s architecture and user experience without copying its source code.

Unix/Linux can be abstracted into three layers: kernel (low level), shell (command interpreter), and application (high level).

1) Kernel Layer

The kernel directly interacts with hardware, manages resources, and provides a stable environment for applications.

2) Shell Layer

The shell is the user interface that interprets commands and displays results.

3) Application Layer

Provides graphical environments based on the X Window protocol.

1.3 Bridge, NAT, Host‑Only

Bridge mode: virtual NIC and physical NIC share the same network segment, suitable for providing services to other PCs on the LAN.

NAT mode: virtual NIC uses network address translation to access external networks; the virtual network is isolated from the physical LAN.

Host‑Only mode: the virtual network can only communicate with the host, no external network access.

NAT and bridge comparison: Both allow VMs to access the Internet. In NAT mode, only the host can reach the VM; the VM can reach the LAN. In bridge mode, VMs are on the same subnet as physical machines and can communicate directly.

2. Linux Practical Commands

2.1 Runlevel Management

0: Halt

1: Single‑user (useful for password recovery)

2: Multi‑user without network services

3: Multi‑user with network services

4: Reserved

5: Graphical interface

6: Reboot (do not set to 6 permanently)

Modify the default runlevel in /etc/inittab (e.g., id:5:initdefault).

Switching Runlevel

init 3

Example: switch to single‑user mode then to graphical interface.

2.2 Help Commands

man

Usage: man [command] – view manual pages.

help

Usage: help [builtin] – display help for shell built‑ins.

2.3 File and Directory Commands

pwd

Show current working directory.

pwd

ls

List directory contents.

ls -a   # show all files, including hidden
ls -l   # long format

cd

Change directory.

cd /path/to/dir

mkdir

Create directories.

mkdir newdir
mkdir -p /path/to/multi/level

rmdir

Remove empty directories. rmdir emptydir To remove non‑empty directories:

rm -rf dir

touch

Create an empty file.

touch file.txt

cp

Copy files or directories.

cp source.txt dest/
cp -r sourcedir dest/

rm

Delete files or directories.

rm file.txt
rm -r dir
rm -f file.txt   # force

mv

Move or rename files.

mv oldname.txt newname.txt
mv file.txt /target/dir/

cat

Display file contents. cat file.txt Use with | more for pagination.

more

Paginated view of a file.

more file.txt

less

Advanced paginated view with navigation.

less file.txt

Redirection

Overwrite: ls -l > file.txt Append:

ls -al >> file.txt

echo

Print text or variables.

echo $PATH
echo "Hello, world!"

head

Show beginning of a file (default 10 lines).

head file.txt
head -n 5 file.txt

tail

Show end of a file (default 10 lines).

tail file.txt
tail -n 5 file.txt
tail -f file.txt   # follow updates

ln

Create symbolic links. ln -s /original/path linkname Remove a symlink with rm -rf linkname.

2.4 Date and Time

date

– display current date/time. date +%Y – year. date +%m – month. date +%d – day. date "+%Y-%m-%d %H:%M:%S" – full timestamp.

Set system time:

date -s "2021-05-20 05:20:20"

2.5 Calendar

cal

– show current month; cal 2023 – show full year.

2.6 Search Commands

find

Recursive search.

find /path -name "pattern" -size +20M

locate

Fast lookup using a prebuilt database.

updatedb   # update database
locate filename

grep

Search within files.

grep -n "text" file.txt
grep -i "pattern" file.txt

2.7 Compression and Archiving

gzip / gunzip

gzip file.txt   # creates file.txt.gz
gunzip file.txt.gz

zip / unzip

zip -r archive.zip dir/   # compress directory
unzip -d /target/dir archive.zip

tar

tar -cvzf archive.tar.gz dir/   # create compressed archive
tar -xvzf archive.tar.gz   # extract archive
Linux command example
Linux command example
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Shellcommand-lineUnixSystem Administration
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.