Master Linux Basics: From Installation to Shell Scripting in One Guide
This comprehensive tutorial walks you through Linux fundamentals, covering VMware installation, network configuration, essential command usage, user management, software installation methods, shell scripting basics, process management, cron jobs, and awk text processing, all illustrated with step‑by‑step screenshots and code examples.
Linux General Knowledge
Linux powers most servers, cloud platforms, and big‑data tools, yet many learners start with Windows; this guide shows why mastering Linux is essential for personal growth and professional development.
1. VMware Installation
What is a virtual machine?
A virtual machine emulates a complete hardware system, allowing independent OS installations.
Download the VMware installer from the official site and unzip it.
Run the installer by double‑clicking the executable.
Accept the license agreement.
Choose an installation directory (avoid non‑ASCII characters).
Select user‑experience options as desired.
Create a desktop and start‑menu shortcut.
Enter the license key ZG1WH-ATY96-H80QP-X7PEX-Y30V4 when prompted.
Finish the installation and launch VMware.
After launching, create a new virtual machine, select Custom , choose Linux CentOS 7 , allocate memory (not exceeding host RAM), set the network type to NAT , select LSILogic for the controller, create a new virtual disk, and finish the wizard.
2. Network Configuration
Configure the newly created CentOS VM for external network access.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0Edit the file with the following content:
DEVICE=eth0 # Device name
BOOTPROTO=dhcp # Use DHCP for IP assignment
HWADDR=00:0C:29:AD:66:9F # Hardware MAC address
ONBOOT=yes # Activate on bootRestart the network service and test connectivity:
service restart network
ping www.baidu.com3. Installing Xshell
Use a remote terminal to manage the VM.
Xshell is a Windows SSH client that provides secure remote access and customizable appearance.
Download Xshell (note: the original source warns of slow download).
Ensure port 22 is open on the CentOS VM.
Configure appearance, fonts, and colors via the File → Properties menu.
4. Common Linux Commands
Key commands frequently used in daily operations.
cd ~– Switch to the user’s home directory. cd / – Go to the root directory. cd .. – Move up one directory level. ls – List files in the current directory. ls -la – List all files, including hidden ones, with details. pwd – Show the absolute path of the current directory. cp source dest – Copy files. rm file – Delete files. q! – Exit an editor without saving. wq! – Save and exit. hostname – Display the host name. ifconfig – Show network interface information. firewall-cmd --state – Check firewall status on CentOS 7.
5. User Management
Creating and switching users.
useradd -d /home/lanj -m lanj # Create user "lanj"
passwd lanj # Set password for "lanj"
su - lanj # Switch to user "lanj"
su - root # Switch to root (requires password)6. Software Installation Methods
Three common ways to install software on Linux.
6.1 Source Installation
Download and extract the source code, read the README for prerequisites, then compile and install using make and make install. Example Makefile snippet:
edit: main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
main.o: main.c defs.h
cc -c main.c
... (other object rules) ...
clean:
rm edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o6.2 RPM Installation
RPM packages contain pre‑compiled binaries. Example package name server-2.1.0-22.i386.rpm where server is the software name, 2.1.0 the version, 22 the release, and i386 the architecture.
6.3 YUM Installation
Check if YUM exists and install it if missing:
rpm -qa | grep yum
rpm -ivh yum-*.noarch.rpmConfigure repositories by editing /etc/yum.repos.d/CentOS-Base.repo. Popular repos include EPEL and RPMForge .
7. Shell Basics
Understanding the shell and writing scripts.
The shell interprets commands entered by the user. A simple script ( hello.sh) looks like:
#!/bin/bash
# Tell the system to use Bash
echo "Hello xiaolan!"Make it executable with chmod +x hello.sh and run it with ./hello.sh or /bin/sh hello.sh.
Variables
Define variables without spaces around the = sign:
James="小皇帝"
echo $JamesMark a variable as read‑only with readonly, delete with unset, and distinguish between local, environment, and shell variables.
Arrays
array=(value1 value2 value3)
echo ${array[0]} # value1
echo ${array[@]} # all elements
echo ${#array[@]} # lengthControl Structures
Examples of if, for, while, case, break, and continue statements are provided, showing condition checks, loops, and exit mechanisms.
Functions
Fun1(){
echo "This is my first shell function!"
}
Fun1Redirection
Redirect output with > (overwrite) or >> (append). Discard output using /dev/null. Standard file descriptors: 0 = stdin, 1 = stdout, 2 = stderr.
Operators
Arithmetic, relational, boolean, logical, and string operators are demonstrated (e.g., +, -eq, &&, ||, ==).
8. Process Management, Cron Jobs, and Background Execution
Scheduling tasks with crontab and running jobs in the background.
crontab -eopens the user’s crontab file. Each line follows the format: minute hour day month week command Special symbols: * – any value , – list separator - – range / – step interval
Examples:
# Daily backup at 5 AM
0 5 * * * /root/bin/backup.sh
# Every five minutes
*/5 * * * * /root/bin/check-status.sh
# Weekdays at 23:59
59 23 * * 1-5 /root/bin/backup.shOther useful commands: crontab -l – list current jobs crontab -r – remove the crontab
9. Running Jobs in the Background
Use nohup and & to keep processes alive after logout.
nohup command &The output is written to nohup.out unless redirected.
10. awk Text‑Processing Tool
Powerful line‑oriented processing.
Basic usage: awk -F ':' '{print $1}' /etc/passwd Built‑in variables such as FILENAME, NR, NF, FS, RS, OFS, and ORS control input and output formatting.
Common functions include toupper(), tolower(), length(), substr(), sin(), cos(), sqrt(), and rand(). Conditional statements and loops ( if, for, while, case) enable complex data extraction, such as filtering IP addresses, finding the largest memory‑consuming process, or checking file existence.
Signed-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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
