Fundamentals 58 min read

Master Linux Basics: Essential Commands, Shell, and System Management

This comprehensive guide walks you through Linux fundamentals, covering operating system concepts, shell types, essential command-line tools, file and directory operations, user and permission management, process monitoring, networking, package handling, compression, compilation, backup, and Vim editing techniques, all with clear examples and practical tips.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Basics: Essential Commands, Shell, and System Management

Introduction

Learning Linux is essential for programmers, yet front‑end developers often have fewer opportunities to work with it compared to back‑end developers. This article provides a thorough introduction to Linux basics, assuming you have access to an Alibaba Cloud ECS instance running CentOS 7.7 or a local virtual machine.

Linux Fundamentals

Linux is an operating system (OS) that sits directly on hardware, providing core services such as memory management, process scheduling, and basic I/O. The OS kernel (the "Operating System") interacts with hardware, while distributions ("Linux distributions") bundle the kernel with additional software packages.

Key differences between Linux and Windows include stability, cost, rapid security patches, multitasking, user permissions, embedded‑system suitability, and lower resource consumption.

Linux Distributions

Red Hat Enterprise Linux (RHEL) – commercial, widely used in production.

Fedora – community edition that feeds features into RHEL.

CentOS – free rebuild of RHEL.

Deepin – Chinese distribution with integrated desktop.

Debian – stable, secure, popular worldwide.

Ubuntu – Debian‑based, excellent hardware compatibility, suitable for both desktop and server.

Connecting to an Alibaba Cloud Server

Use SSH to log in: ssh [email protected] Enter the password when prompted.

Shell Overview

The term "Shell" originally means "outer shell" and refers to the command‑line interface (CLI) that lets users interact with the kernel. Common shells include Bourne Shell (sh), Bash (bash), C Shell (csh), TENEX C Shell (tcsh), Korn Shell (ksh), Z Shell (zsh), and Friendly Interactive Shell (fish). Bash is the default on most Linux systems, including macOS.

Check the current shell with echo $SHELL or list all installed shells with cat /etc/shells.

Essential Commands

Command Prompt

The prompt usually ends with a $ for regular users or # for the root user.

Common Commands

pwd

– display the current working directory. whoami – show the current username. hostname – display the host name.

Command Syntax

General form:

command parameters

Parameters

Short options: -a (e.g., ls -a shows all files, including hidden).

Long options: --all.

Combined short and long: ls --all -l.

Useful Shortcuts

↑/↓ – navigate command history.

Tab – autocomplete commands or file names.

Ctrl + R – reverse search command history.

Ctrl + L – clear the screen.

Ctrl + C – abort the current command.

Ctrl + U – delete from cursor to line start.

Ctrl + K – delete from cursor to line end.

Ctrl + W – delete the previous word.

Ctrl + Y – paste the last killed text.

Ctrl + A / Ctrl + E – move cursor to line start/end.

Ctrl + D – exit the shell.

File and Directory Operations

Viewing Paths

pwd

shows the current directory path.

Finding Executables

which command

displays the full path of the executable that will run.

Listing Files

ls

lists files and directories. Common options: -a – include hidden files. -l – long format with permissions. -h – human‑readable sizes. -t – sort by modification time. -i – show inode numbers.

Changing Directories

Use cd followed by a path. Examples:

cd /          # root directory
cd ~          # home directory
cd ..         # parent directory
cd ./home      # subdirectory "home" of current directory
cd /home/lion # absolute path
cd            # shortcut to home

Disk Usage

du

reports directory sizes. Useful options: -h – human‑readable. -a – include files. -s – show only total.

Viewing File Contents

cat file

– display entire file (good for small files). less file – paginate view (good for large files). Navigation keys: Space (next page), b (previous page), Enter (next line), y (previous line), d (half‑page forward), u (half‑page back), q (quit), = (show line numbers), h (help), / (search). head file – show first 10 lines (default) or use -n N for N lines. tail file – show last 10 lines; -f follows new output.

Creating and Removing Files

touch new_file          # create empty file
rm new_file             # delete file
rm -f file              # force delete
rm -r directory        # recursive delete (use with caution)

Links

Hard links share the same inode; deleting one does not affect the other. Soft (symbolic) links are shortcuts that point to another pathname.

ln file1 file2          # hard link
ln -s target link       # symbolic link

User and Permission Management

Users

Linux is multi‑user. The superuser root has unrestricted access. Regular users have limited permissions and can gain temporary elevated rights with sudo.

Creating Users and Groups

useradd lion            # add user "lion"
passwd lion            # set password
groupadd friends        # create group
usermod -g friends lion # change lion's primary group

Switching Users

su - lion               # switch to lion
sudo su                 # become root (requires password)

Changing Ownership and Permissions

chown lion file.txt                # change owner
chown lion:staff file.txt          # change owner and group
chmod 740 file.txt                 # set rwx for owner, r for group, none for others
chmod -R 777 /home/lion           # recursive change

Permission bits: r (read), w (write), x (execute). The first character indicates file type ( d for directory, - for regular file, l for link).

Process Management

Viewing Processes

w

– shows who is logged in and what they are doing. ps -ef – snapshot of all processes. top – dynamic, real‑time process monitor.

Controlling Processes

kill 956               # terminate process 956
kill -9 7291           # force kill

Job Control

Append & to run a command in the background. Use bg %1 to resume a stopped job, fg %1 to bring it to the foreground, and jobs to list background jobs. nohup prevents a job from terminating when the terminal closes.

Daemons and systemd

Daemons are background services whose parent PID is 1. systemd is the init system (PID 1) that manages services. Common commands:

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx   # start on boot
systemctl disable nginx  # disable on boot

Package Management

YUM (CentOS/RHEL)

yum update               # update packages
yum install vim         # install a package
yum remove vim          # remove a package
yum search nginx

Switching YUM Mirrors

Backup the original repo file, download a mirror (e.g., Alibaba Cloud), then run yum makecache to refresh.

Compression and Archiving

tar

tar -cvf archive.tar dir/          # create archive
tar -xvf archive.tar                # extract
tar -tvf archive.tar                # list contents

gzip / gunzip

gzip archive.tar      # creates archive.tar.gz
gunzip archive.tar.gz

tar with gzip

tar -zcvf archive.tar.gz dir/   # create and compress
tar -zxvf archive.tar.gz         # extract

zip / unzip

zip -r archive.zip dir/
unzip archive.zip

Compiling Software from Source

Typical steps: download source, extract, ./configure, make, make install. Example with htop:

# download
wget https://example.com/htop-3.0.0.tar.gz
# extract
tar -zxvf htop-3.0.0.tar.gz
cd htop-3.0.0
# configure, compile, install
./configure
make
sudo make install

Networking

ifconfig / ip

Show network interfaces. Install net-tools if ifconfig is missing.

host

host github.com          # resolve to IP
host 8.8.8.8           # reverse lookup

SSH

ssh [email protected]          # connect to remote host
# ~/.ssh/config example
Host lion
    HostName 172.31.24.78
    User root
    Port 22

After configuring, you can simply run ssh lion. For password‑less login, generate a key pair with ssh-keygen and copy the public key to the server using ssh-copy-id.

wget

wget https://example.com/file.zip
wget -c https://example.com/large.iso   # continue interrupted download

Backup Tools

scp

scp file.txt [email protected]:/root/   # copy to remote
scp [email protected]:/root/file.txt ./   # copy from remote

rsync

rsync -arv Images/ backups/               # local backup
rsync -arv Images/ [email protected]:/backups/   # remote sync

Use --delete to remove files on the destination that no longer exist on the source.

System Control

halt          # shut down (requires root)
reboot        # restart (requires root)
poweroff     # power off (may not require root)

Vim Editor

What Is Vim?

Vim is an enhanced version of the classic vi editor, offering powerful features such as syntax highlighting, code completion, and extensive configurability. It is a favorite among developers on Unix‑like systems.

Modes

Normal (command) mode – default, for navigation and manipulation.

Insert mode – press i, a, o etc. to edit text.

Command‑line mode – press : to execute commands like :wq.

Visual mode – press v, V, or Ctrl+v to select text for operations.

Basic Operations

Move cursor: h left, j down, k up, l right (or arrow keys).

Start of line: 0 or Home. End of line: $ or End.

Delete character: x. Delete N characters: Nx.

Delete line: dd. Delete N lines: Ndd.

Delete word: dw. Delete to line start: d0. Delete to line end: d$.

Copy (yank) line: yy. Copy word: yw. Paste: p.

Undo: u. Redo: Ctrl+r.

Search: /pattern then n (next) or N (previous).

Replace on current line: :s/old/new/. Replace all on line: :s/old/new/g. Replace in range: n,m s/old/new/g. Replace in whole file: :%s/old/new/g.

Advanced Features

Insert another file at cursor: :r filename.

Split windows: :sp file (horizontal) or :vsp file (vertical). Navigate splits with Ctrl+w followed by arrow keys or Ctrl+w w.

Run external commands: :!ls.

Visual block mode ( Ctrl+v) for column editing – select a block, press I to insert text on each line, then Esc to apply.

Configuration (.vimrc)

Create ~/.vimrc to make settings permanent. Example:

set number          " show line numbers
syntax on           " enable syntax highlighting
set showcmd         " display incomplete commands
set ignorecase      " case‑insensitive search
set mouse=a         " enable mouse support

Further customizations and plugin managers are available on GitHub.

Conclusion

This guide equips you with a solid foundation in Linux command‑line usage, system administration, and Vim editing, enabling you to work efficiently on servers and development environments.

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.

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