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.
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
Linuxkernel 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 parametersShort 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 shortOption Values
ssh [email protected] -p 22 ssh [email protected] --port=22Shortcuts
↑/↓ 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
pwdViewing Executable Paths
which commandListing 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 numbersCreating Files and Directories
touch new_file mkdir new_folder mkdir -p one/two/threeCopying and Moving
cp file file_copy cp -r src_dir dest_dir mv file new_nameDeleting and Linking
rm file rm -rf dir ln source link # hard link ln -s source link # symbolic linkUser 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 - lionGroups
groupadd friends groupdel foo groups lion usermod -g friends lion usermod -G friends,foo,bar lionFile Permissions
chmod 740 file.txt chmod -R 777 /home/lionPermission 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.txtfind
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 nginxSwitching 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 makecacheManual 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 /etcsort
sort name.txt -o name_sorted.txtwc
wc -l file.txt # line countuniq
uniq file.txtcut
cut -d , -f 1 file.csvRedirection, 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 stderrInput Redirection
cat < file.txt command <<END
...text...
ENDPipes
ls -l | grep "^d" du -h | sort -nr | headProcess Management
Viewing Processes
w ps -ef topKilling Processes
kill 1234 kill -9 5678Job Control
command & # background bg %1 # resume background job fg %1 # bring job to foreground jobs # list jobsDaemons and systemd
systemctl start nginx systemctl enable nginx systemctl status nginxCompression and Archiving
tar
tar -cvf archive.tar dir/ tar -xvf archive.targzip
gzip archive.tar gunzip archive.tar.gztar + gzip
tar -zcvf archive.tar.gz dir/ tar -zxvf archive.tar.gzzip
zip -r archive.zip dir/ unzip archive.zipCompiling Software from Source
Typical steps: download source, extract, ./configure, make, make install. Example with htop shown.
Networking
ifconfig
ifconfig eth0host
host github.comSSH
ssh user@hostConfigure /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.zipBackup
scp
scp file.txt user@host:/path/rsync
rsync -arv src/ dest/ rsync -arv src/ user@host:/dest/System Control
halt reboot poweroffVim 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/gAdvanced 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=aThese 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
Java Interview Crash Guide
Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.
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.
