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.
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 3Example: 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.
pwdls
List directory contents.
ls -a # show all files, including hidden ls -l # long formatcd
Change directory.
cd /path/to/dirmkdir
Create directories.
mkdir newdir mkdir -p /path/to/multi/levelrmdir
Remove empty directories. rmdir emptydir To remove non‑empty directories:
rm -rf dirtouch
Create an empty file.
touch file.txtcp
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 # forcemv
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.txtless
Advanced paginated view with navigation.
less file.txtRedirection
Overwrite: ls -l > file.txt Append:
ls -al >> file.txtecho
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.txttail
Show end of a file (default 10 lines).
tail file.txt tail -n 5 file.txt tail -f file.txt # follow updatesln
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 +20Mlocate
Fast lookup using a prebuilt database.
updatedb # update database locate filenamegrep
Search within files.
grep -n "text" file.txt grep -i "pattern" file.txt2.7 Compression and Archiving
gzip / gunzip
gzip file.txt # creates file.txt.gz gunzip file.txt.gzzip / unzip
zip -r archive.zip dir/ # compress directory unzip -d /target/dir archive.ziptar
tar -cvzf archive.tar.gz dir/ # create compressed archive tar -xvzf archive.tar.gz # extract archiveSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
