Fundamentals 28 min read

Master Linux Basics: Installation, VM Setup, Shell Scripting and System Tools in One Guide

This comprehensive tutorial walks you through why Linux matters, how to install VMware, create and configure a CentOS VM, set up networking, use Xshell, master essential commands, manage users, install software via source, RPM or YUM, and write functional Bash scripts with practical examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Basics: Installation, VM Setup, Shell Scripting and System Tools in One Guide

1. Install VMware Workstation and create a CentOS 7 VM

Download the VMware installer, unzip it and run the installer. Accept the license agreement, choose an installation directory without non‑ASCII characters, and enable desktop shortcuts.

Open VMware, click New Virtual Machine and select Custom (advanced) .

Choose Linux → CentOS 7 64‑bit as the guest OS.

Allocate CPU cores and RAM (do not exceed the host’s available memory).

Set the network type to NAT .

Select LSILogic as the I/O controller and SCSI as the disk type.

Create a new virtual disk, specify a custom path (avoid Chinese characters), and finish the wizard.

Create new virtual disk
Create new virtual disk

2. Configure network inside the VM

Edit the interface configuration file /etc/sysconfig/network-scripts/ifcfg-eth0:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp   # obtain IP via DHCP
HWADDR=00:0C:29:AD:66:9F   # optional, use the MAC shown by ifconfig
ONBOOT=yes

Restart the network service ( service network restart) and verify connectivity with ping www.baidu.com (or any reachable host).

3. Remote access with Xshell

Install Xshell (or any SSH client) on the host Windows system. Ensure that port 22 is open in the CentOS firewall (

firewall-cmd --add-service=ssh --permanent && firewall-cmd --reload

) and connect to the VM’s IP address.

4. Essential Linux commands

cd ~

– change to the current user’s home directory. cd / – go to the root directory. cd /path/to/dir – change to a specific directory. ls – list files in the current directory. ls -la – list all files, including hidden ones, with details. pwd – display the absolute path of the current directory. cp source dest – copy files. rm file – delete a file. ifconfig – show network interface information. firewall-cmd --state – check firewalld status on CentOS 7.

5. User management

# Add a new user with a home directory
useradd -d /home/lanj -m lanj
# Set the password
passwd lanj
# Switch to the new user
su - lanj
# Switch back to root (requires password)
su - root

6. Software installation methods

6.1 Build from source

Typical workflow:

# Download and extract the source tarball
./configure
make
make install   # installs to /usr/local by default

The configure script checks for required libraries; make compiles the code according to the generated Makefile, and make install copies binaries, libraries and documentation.

6.2 RPM packages

RPM files contain pre‑compiled binaries. Install with: rpm -ivh package.rpm RPM packages are tied to a specific distribution version and architecture (e.g., server-2.1.0-22.i386.rpm).

6.3 YUM repositories

Check whether YUM is installed: rpm -qa | grep yum If missing, install it: rpm -ivh yum-*.noarch.rpm Configure additional repositories by editing /etc/yum.repos.d/Centos-Base.repo (e.g., enable EPEL or RPMForge).

7. Bash shell basics

A Bash script starts with a shebang that tells the kernel which interpreter to use:

#!/bin/bash

echo "Hello xiaolan!"

Variables

Variable names may contain letters, digits and underscores, but must not start with a digit or a Bash keyword. Reference a variable with $VAR or ${VAR}:

#!/bin/bash
James="小皇帝"
echo $James

Read‑only variables

readonly James
# Attempting to modify James now fails

Arrays

array=(value1 value2 value3)
# Access elements
echo ${array[0]}          # value1
echo ${array[@]}          # all elements
echo ${#array[@]}         # length of the array

Control structures

Typical Bash constructs:

# if … then … elif … else … fi
if [ $a -gt $b ]; then
    echo "a is greater"
elif [ $a -eq $b ]; then
    echo "a equals b"
else
    echo "a is smaller"
fi

# for loop
for i in 1 2 3 4 5; do
    echo "The value is: $i"
done

# while loop
i=1
while (( i <= 6 )); do
    echo $i
    ((i++))
done

# case statement
read -p "Enter a number (1‑3): " num
case $num in
    1) echo "You chose 1";;
    2) echo "You chose 2";;
    3) echo "You chose 3";;
    *) echo "Invalid choice";;
esac

Functions

fun1() {
    echo "First shell function"
}
fun1

Redirection

Standard output can be redirected with > (overwrite) or >> (append). Errors are redirected with 2>&1. The null device discards output:

# Write output to a file
ls -l > dir.txt
# Append
ls -l >> dir.txt
# Discard both stdout and stderr
somecommand > /dev/null 2>&1

8. Text processing with awk

awk

reads a file line‑by‑line, splits each line into fields (default delimiter: whitespace) and executes the supplied actions.

# Print the first field of /etc/passwd
awk -F ':' '{print $1}' /etc/passwd

# Print odd‑numbered lines
awk 'NR % 2 == 1 {print $0}' file.txt

# Built‑in variables
# FILENAME – current file name
# NR – total record number
# NF – number of fields in the current record
# $NF – last field of the current line

9. Scheduling with crontab

Crontab runs commands at specified times. The schedule format is: minute hour day month week command Examples:

# Daily backup at 05:00
0 5 * * * /root/bin/backup.sh

# Weekdays at 23:59
59 23 * * 1-5 /root/bin/backup.sh

# Every 5 minutes
*/5 * * * * /root/bin/check-status.sh

Common options: crontab -e – edit the current user’s crontab. crontab -l – list the crontab entries. crontab -r – remove the crontab.

10. Running commands in the background

Use nohup to keep a process alive after logout. Output is written to nohup.out unless redirected.

nohup long_running_task &

Alternatively, append & to any command to run it in the background (e.g., my_script.sh &).

11. Summary

This guide provides a practical workflow for setting up a CentOS 7 virtual machine on Windows, configuring networking, managing users, installing software via source, RPM or YUM, writing and debugging Bash scripts, processing text with awk, scheduling recurring tasks with crontab, and running long‑lived processes with nohup. Mastering these fundamentals equips beginners with the core skills required for modern Linux system administration.

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.

LinuxShellcommand-lineVMwareSystem Administration
Liangxu Linux
Written by

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.)

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.