Fundamentals 57 min read

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

This comprehensive guide introduces Linux fundamentals, covering core concepts, essential commands, file and directory operations, user and permission management, process handling, networking, software installation, compression, backup, and Vim editor usage, providing practical examples and clear explanations for developers and system administrators.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Master Linux Basics: Essential Commands, Shell, System Management, and Vim Editing

Preface

Learning Linux is essential for programmers, especially front‑end developers who have fewer opportunities to work with it compared to back‑end developers. The author uses an Alibaba Cloud ECS instance (CentOS 7.7 64‑bit) but you can also install CentOS in a virtual machine for free.

Linux Basics

Operating System

An operating system (OS) is the first layer of software on hardware, providing basic services, managing resources, and acting as a bridge between hardware and other software.

What is Linux

Linux Kernel vs. Distribution

Linux

kernel is maintained by Linus Torvalds and provides hardware abstraction, file system control, and multitasking. Linux distribution combines the kernel with a collection of common software to form a complete operating system.

Summary: The kernel is the core; a distribution is the full OS.

Linux vs. Windows

Stable and efficient

Free (or low cost)

Fewer vulnerabilities and fast patches

Multitasking and multi‑user

Better security model

Suitable for embedded systems

Relatively low resource consumption

Linux Distributions

RHEL – widely used in enterprise

Fedora – community edition, upstream of RHEL

CentOS – free rebuild of RHEL

Deepin – Chinese distribution

Debian – stable and secure

Ubuntu – Debian‑based, desktop and server

Connecting to Alibaba Cloud Server

Use ssh [email protected] and enter the password to log in.

Shell

The word "Shell" means "outer shell" and refers to the command‑line interface (CLI) that lets users interact with the kernel. It interprets commands, supports variables, conditionals, loops, and scripts.

Shell Types

Bourne Shell (sh)

Bourne Again Shell (bash) – most common

C Shell (csh)

TENEX C Shell (tcsh)

Korn Shell (ksh)

Z Shell (zsh)

Friendly Interactive Shell (fish)

Use echo $SHELL to view the current shell and cat /etc/shells to list all installed shells.

Commands

Command Prompt

The prompt ends with $ for normal users or # for root.

Command Syntax

command parameters

Short and Long Options

ls -a            # show all files
ls -al           # list all with details
ls --all         # long option
ls --all -l      # mix of long and short

Option Values

ssh [email protected] -p 22
ssh [email protected] --port=22

Shortcuts

↑/↓ to recall history

Tab for completion

Ctrl+R to search history

Ctrl+L to clear screen

Ctrl+C to abort

Ctrl+U to cut to line start

Ctrl+K to cut to line end

Ctrl+W to delete previous word

Ctrl+Y to paste

Ctrl+A/E to jump to line start/end

Ctrl+D to close the shell

Files and Directories

File Organization

Files consist of a name, content, and permissions; the name is linked to the file’s inode.

Viewing Paths

pwd

Viewing Executable Paths

which command

Listing Files

ls -a    # all files including hidden
ls -l    # detailed list
ls -h    # human‑readable sizes
ls -t    # sort by modification time
ls -i    # show inode numbers

Creating Files and Directories

touch new_file
mkdir new_folder
mkdir -p one/two/three

Copying and Moving

cp file file_copy
cp -r src_dir dest_dir
mv file new_name

Deleting and Linking

rm file
rm -rf dir
ln source link   # hard link
ln -s source link   # symbolic link

User and Permissions

Users

Linux is multi‑user. The root user has full privileges. Regular users have limited rights and can use sudo for elevated commands.

Managing Users

useradd lion
passwd lion
userdel lion
su - lion

Groups

groupadd friends
groupdel foo
groups lion
usermod -g friends lion
usermod -G friends,foo,bar lion

File Permissions

chmod 740 file.txt
chmod -R 777 /home/lion

Permission bits: r read, w write, x execute; - means no permission. The three groups are owner, group, others.

Searching Files

locate

yum -y install mlocate
updatedb
locate file.txt

find

find . -name "*.txt"
find /var -size +10M
find . -type f -exec chmod 600 {} \;

Software Repositories

CentOS uses yum to manage RPM packages.

yum update
yum search nginx
yum install nginx
yum remove nginx

Switching Mirrors

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

Manual Pages

Use man command to read documentation. Sections include user commands, system calls, libraries, files, games, miscellaneous, system administration, and kernel.

Advanced Linux

Text Operations

grep

grep -i pattern file
grep -r hello /etc

sort

sort name.txt -o name_sorted.txt

wc

wc -l file.txt   # line count

uniq

uniq file.txt

cut

cut -d , -f 1 file.csv

Redirection, Pipes, and Streams

Standard streams: stdin, stdout, stderr.

Redirection

command > file.txt      # overwrite
command >> file.txt     # append
command 2> error.log   # redirect stderr
command > out.txt 2>&1   # combine stdout and stderr

Input Redirection

cat < file.txt
command <<END
...text...
END

Pipes

ls -l | grep "^d"
du -h | sort -nr | head

Process Management

Viewing Processes

w
ps -ef
top

Killing Processes

kill 1234
kill -9 5678

Job Control

command &          # background
bg %1               # resume background job
fg %1               # bring job to foreground
jobs                # list jobs

Daemons and systemd

systemctl start nginx
systemctl enable nginx
systemctl status nginx

Compression and Archiving

tar

tar -cvf archive.tar dir/
tar -xvf archive.tar

gzip

gzip archive.tar
gunzip archive.tar.gz

tar + gzip

tar -zcvf archive.tar.gz dir/
tar -zxvf archive.tar.gz

zip

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

Compiling Software from Source

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

Networking

ifconfig

ifconfig eth0

host

host github.com

SSH

ssh user@host

Configure /etc/ssh/sshd_config (Port, PermitRootLogin, PasswordAuthentication, PubkeyAuthentication) and client ~/.ssh/config (Host, HostName, Port, User). Set up key‑based authentication with ssh-keygen and ssh-copy-id.

wget

wget http://example.com/file.zip

Backup

scp

scp file.txt user@host:/path/

rsync

rsync -arv src/ dest/
rsync -arv src/ user@host:/dest/

System Control

halt
reboot
poweroff

Vim Editor

Vim has four modes: Normal (interactive), Insert, Command, and Visual. Use i to enter Insert mode, Esc to return to Normal mode, : to enter Command mode, and v / V / Ctrl+v for Visual selections.

Basic Operations

Open: vim file.txt Insert: i Move cursor: h/j/k/l or arrow keys

Delete character: x Delete line: dd Copy line: yy Paste: p Undo: u, redo: Ctrl+r Search: /pattern, next n, previous N Replace:

:%s/old/new/g

Advanced Features

Split windows: :sp file (horizontal), :vsp file (vertical)

Navigate splits: Ctrl+w followed by direction or Ctrl+w Ctrl+w Run external commands: :!ls Visual block mode: Ctrl+v for column editing

Vim Configuration

Create ~/.vimrc with options such as:

set number
syntax on
set showcmd
set ignorecase
set mouse=a

These settings enable line numbers, syntax highlighting, command echo, case‑insensitive search, and mouse support.

Conclusion

After studying this guide you should have a solid understanding of Linux fundamentals, command‑line usage, system administration, and Vim editing, empowering you to work efficiently on Linux‑based environments.

References

[1] bintray.com/htop/source…:

https://link.juejin.cn/?target=https%3A%2F%2Fbintray.com%2Fhtop%2Fsource%2Fhtop%23files

LinuxVimSystem Administration
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

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.