1. Introduction to Linux
Linux is an open-source Unix-like operating system kernel, first released by Linus Torvalds in 1991. Today, Linux has become a mainstream operating system in fields such as servers, embedded devices, and supercomputers.
Linux Distributions
Ubuntu – A popular distribution suitable for beginners
CentOS/RHEL – Commonly used in enterprise-level servers
Debian – A stable and reliable distribution
Arch Linux – A rolling release distribution aimed at advanced users
Fedora – A community distribution supported by Red Hat
2. Basic Commands
File System Operations
pwd # Display current working directory
ls # List directory contents
ls -l # Detailed list
ls -a # Show hidden files
cd directory_name # Change directory
mkdir directory # Create directory
rmdir directory # Remove empty directory
touch file # Create empty file
rm file # Remove file
rm -r directory # Recursively remove directory
cp source target # Copy file/directory
mv source target # Move/rename file/directory
File Viewing and Editing
cat file # Display file content
less file # View file page by page
head file # Show the beginning of the file
tail file # Show the end of the file
nano file # Simple text editor
vi/vim file # Advanced text editor
System Information
uname -a # Display system information
df -h # Show disk usage
free -h # Show memory usage
top # Display process information
ps aux # Show all processes
Permission Management
chmod permissions file # Change file permissions
chown user:group file # Change file owner
sudo command # Execute command with superuser privileges
su username # Switch user
3. User and Group Management
useradd username # Add user
passwd username # Set user password
userdel username # Delete user
groupadd group_name # Add group
usermod -aG group_name username # Add user to group
4. Network Related Commands
ifconfig # Display network interface information (old version)
ip addr # Display network interface information (new version)
ping host # Test network connection
netstat -tuln # Show network connections and listening ports
ssh user@host # Remote login
scp file user@host:path # Securely copy file
wget URL # Download file
curl URL # Transfer data
5. Package Management
Debian/Ubuntu (APT)
sudo apt update # Update package list
sudo apt upgrade # Upgrade all packages
sudo apt install package_name # Install package
sudo apt remove package_name # Remove package
sudo apt search keyword # Search for package
RHEL/CentOS (YUM/DNF)
sudo yum update # Update all packages (YUM)
sudo dnf update # Update all packages (DNF)
sudo yum install package_name # Install package (YUM)
sudo dnf install package_name # Install package (DNF)
sudo yum remove package_name # Remove package (YUM)
6. Process Management
ps aux # View all processes
top # Dynamically view processes
htop # Enhanced version of top (requires installation)
kill PID # Terminate process
kill -9 PID # Force terminate process
bg # Run suspended process in background
fg # Bring background process to foreground
jobs # Display background processes
7. File Permissions
Linux file permissions are divided into three categories:
Owner (u)
Group (g)
Other users (o)
Permission Types:
Read (r)=4
Write (w)=2
Execute (x)=1
Example:
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chmod +x file # Add execute permission
8. Basic Shell Scripting
A simple shell script example:
#!/bin/bash
# This is a comment
echo "Hello, World!"
Run the script:
chmod +x script_name.sh
./script_name.sh
9. Common Shortcuts
Ctrl+C: Terminate current command
Ctrl+D: Exit current shell
Ctrl+Z: Suspend current process
Ctrl+A: Move to the beginning of the line
Ctrl+E: Move to the end of the line
Ctrl+R: Search command history
Tab: Command/file name auto-completion