Introduction to Common Linux Commands

When using the resources of the National Supercomputing Center, teachers often find themselves at a loss with the Linux command line. This article systematically organizes the commonly used Linux system commands to provide valuable references for teachers and students.Introduction to Common Linux CommandsWe typically categorize common Linux commands into several groups: file operations, process management, system information, network operations, permission management, compression and packaging, etc. Below, we will list some of the most commonly used commands and provide brief explanations.1. File and Directory Operations

ls # List directory contents

ls -l # Detailed list

ls -a # Show hidden files

ls -lh # Human-readable file sizes

cd # Change directory

cd ~ # Go to home directory

cd – # Return to the previous directory

cd .. # Parent directory

pwd # Display current directory path

mkdir # Create directory

mkdir -p # Create multi-level directories

rmdir # Remove empty directory

2. File Operations

cp # Copy file

cp -r # Recursively copy directory

mv # Move/rename file

rm # Remove file

rm -r # Recursively remove directory

rm -f # Force remove

touch # Create empty file/update timestamp

cat # Display file content

cat -n # Display line numbers

less # View file page by page

more # Basic version of paged viewing

head # Display file beginning

head -n 10 # Display first 10 lines

tail # Display file end

tail -f # Real-time track file changes

tail -n 20 # Display last 20 lines

3. File Searching and Finding

find /path -name “*.txt” # Find by name

find . -type f -size +1M # Find files larger than 1MB

find . -mtime -7 # Find files modified in the last 7 days

grep “pattern” file.txt # Search text in file

grep -r “hello” /path # Recursively search directory

grep -i “pattern” # Ignore case

grep -v “exclude” # Exclude matches

locate filename # Quickly find file (requires updatedb)

which command # Show command path

whereis command # Show command location

4. System Information Monitoring

top # Dynamically display processes (similar to Task Manager)

htop # Enhanced version of top (requires installation)

ps # Display process snapshot

ps aux # Display details of all processes

ps -ef # Complete format process list

free -h # Memory usage (human-readable)

df -h # Disk space usage (human-readable)

du -sh # Directory size statistics

uname -a # System kernel information

cat /etc/os-release # System version information

uptime # System uptime and load

who # Current logged-in users

w # Show who is logged in and what they are doing

5. Hardware Information

lscpu # CPU information

lsblk # Block device information

lspci # PCI device information

lsusb # USB device information

6. System Management

chmod # Change file permissions

chmod 755 file # Set permissions rwxr-xr-x

chmod +x script # Add execute permission

chown # Change file owner

chown user:group file

chgrp # Change file group

sudo # Execute command with superuser privileges

su # Switch user

7. Package Management

# Ubuntu/Debian

apt update && apt upgrade

apt install package

apt remove package

dpkg -i package.deb

# CentOS/RHEL/Fedora

yum install package # CentOS/RHEL

dnf install package # Fedora

rpm -ivh package.rpm

# Arch Linux

pacman -S package

8. Network Management

ping host # Test network connectivity

ping -c 4 google.com # Send 4 packets

ifconfig # Network interface configuration (older)

ip addr # Show IP address (recommended)

netstat # Network statistics

netstat -tuln # View listening ports

ss -tuln # Faster netstat alternative

traceroute host # Trace packet path

mtr host # Enhanced version of traceroute

wget url # Download file

wget -c url # Resume download

curl url # Transfer data

curl -O url # Download file

ssh user@host # SSH remote connection

scp file user@host:/path # Secure copy

9. Compression and Decompression

# Common tar combinations

tar -czf archive.tar.gz /path # Create gzip compression

tar -xzf archive.tar.gz # Decompress gzip

tar -cjf archive.tar.bz2 /path # Create bzip2 compression

tar -xjf archive.tar.bz2 # Decompress bzip2

# zip/unzip

zip archive.zip file1 file2

unzip archive.zip

# gzip/bzip2

gzip file # Compress file

gzip -d file.gz # Decompress file

bzip2 file # bzip2 compression

bunzip2 file.bz2 # bzip2 decompression

10. Text Management

wc file # Count lines, words, bytes

wc -l file # Count lines only

sort file # Sort file content

sort -r file # Reverse sort

sort -n file # Numeric sort

uniq file # Remove duplicate lines (requires sorting first)

uniq -c file # Count duplicates

cut -d: -f1 file # Extract fields by delimiter

cut -c1-5 file # Extract character range

awk ‘{print $1}’ file # Powerful text processing

sed ‘s/old/new/g’ file # Stream editor for text replacement

diff file1 file2 # Compare file differences

11. Other Useful Commands

history # Command history

!! # Execute the last command

!n # Execute the nth command in history

alias # Show aliases

alias ll=’ls -l’ # Create alias

echo “text” # Output text

echo $PATH # Output environment variable

date # Display current date and time

cal # Display calendar

man command # View command manual

whatis command # Brief command description

which command # Show command path

ln -s target link # Create symbolic link

12. Common Combination Techniques

# Piping and Redirection

command1 | command2 # Pipe transfer

ls > file.txt # Output redirection to file

ls >> file.txt # Append to file

grep “error” log.txt 2>&1 # Error output redirection

# Background Running

command & # Run in background

nohup command & # Continue running after terminal exit

# Command Combinations

(command1; command2) # Execute in sequence

command1 && command2 # Execute second only if first succeeds

command1 || command2 # Execute second only if first fails

# Find and Process

find . -name “*.log” -exec rm {} \; # Find and delete

grep -r “error” /var/log | wc -l # Count errors

13. Essential Knowledge for Beginners

Use the Tab key for auto-completion

Ctrl+C to interrupt the current command

Ctrl+D to exit terminal or end input

Ctrl+Z to pause process, fg to resume foreground, bg to resume background

clear to clear the screen

Use history | grep keyword to search command history

This list covers 90% of daily usage scenarios. It is recommended to master the basic commands first, and then delve into specific commands as needed.

Leave a Comment