Common Linux Development Commands Manual

1. File and Directory Operations

1. Basic File Operations

ls -alh  # List all files in detail (including hidden files)
cd ~/projects  # Change directory
pwd  # Display current path
mkdir -p dir1/dir2  # Recursively create directories
touch file.txt  # Create an empty file or update the file timestamp
cp -r src dest  # Recursively copy directories
mv old new  # Move/rename files
rm -rf dir  # Forcefully recursively delete directories (use with caution)

2. File Viewing and Searching

cat file  # Display file content
less file  # View file page by page (supports search/page turning)
head -n 10 file  # Display the first 10 lines of a file
tail -f log.log  # Real-time track changes in log files
grep "error" *.log -n  # Search for errors in logs and display line numbers
find /path -name "*.java"  # Find Java files
locate filename  # Quickly find files (requires updatedb first)

2. Text Processing

1. Common Text Processing

awk '{print $1}' file  # Extract the first column
sed 's/foo/bar/g' file  # Replace text
sort file.txt  # Sort file content
uniq file.txt  # Remove consecutive duplicate lines
wc -l file.txt  # Count lines
diff file1 file2  # Compare file differences

2. Advanced Text Processing

# Count occurrences of each error in logs
grep "ERROR" app.log | awk '{print $5}' | sort | uniq -c | sort -nr
# Extract specific fields from JSON
jq '.user.name' data.json

3. System Monitoring and Process Management

1. System Status

top  # Dynamically view system processes (similar to Task Manager)
htop  # Enhanced version of top (requires installation)
free -h  # View memory usage (-h for human-readable format)
df -h  # View disk space
uptime  # View system uptime and load

2. Process Management

ps aux | grep java  # Find Java processes
kill -9 PID  # Forcefully terminate a process
pkill -f "pattern"  # Kill processes by pattern
nohup command &  # Run a program in the background and ignore hangup signals
jobs  # View background tasks
fg %1  # Bring background task 1 to the foreground

4. Networking

1. Network Diagnostics

ifconfig  # View network interfaces (ip addr is more modern)
ping google.com  # Test network connectivity
netstat -tulnp  # View listening ports and corresponding processes
ss -tulnp  # Modern replacement for netstat
traceroute google.com  # Trace network route
curl -v http://example.com  # Detailed HTTP request
wget http://example.com/file.zip  # Download file

2. Firewall and Ports

sudo ufw allow 8080  # Allow port 8080 on Ubuntu
sudo firewall-cmd --add-port=8080/tcp --permanent  # CentOS
sudo iptables -L  # View iptables rules
nc -zv localhost 8080  # Test if port is open

5. Permission Management

1. Users and Permissions

sudo command  # Execute command with root privileges
chmod 755 script.sh  # Change file permissions (rwx)
chown user:group file  # Change file owner
id  # Display current user information
passwd  # Change password

2. ACL Advanced Permissions

setfacl -m u:username:rwx file  # Set ACL permissions
getfacl file  # View ACL permissions

6. Development Toolchain

1. Compilation and Building

gcc -o program source.c  # Compile C program
javac Main.java  # Compile Java
mvn clean package  # Maven build
make  # Execute Makefile

2. Version Control

git init  # Initialize repository
git clone https://github.com/user/repo.git
git status  # View status
git diff  # View changes
git log --oneline --graph  # Compact log display

7. Package Management

1. Debian/Ubuntu (apt)

sudo apt update  # Update package list
sudo apt install package
sudo apt remove package
sudo apt search keyword

2. RHEL/CentOS (yum/dnf)

sudo yum install package
sudo dnf install package  # New version of CentOS

3. General Extraction

tar -xzvf archive.tar.gz  # Extract .tar.gz
unzip file.zip  # Extract zip

8. Shell Tips

1. Practical Tips

ctrl + r  # Search history commands
!!  # Repeat last command
!$  # Last parameter of last command
command | tee output.log  # Output to screen and file simultaneously

2. Environment Variables

echo $PATH  # View PATH variable
export JAVA_HOME=/path/to/jdk  # Temporarily set environment variable
source ~/.bashrc  # Reload bash configuration

9. Containers and Virtualization

1. Common Docker Commands

docker ps -a  # View all containers
docker images  # View images
docker build -t myapp .  # Build Docker image
docker-compose up -d  # Start services in detached mode

2. Common Kubernetes Commands

kubectl get pods  # Get pods
kubectl logs -f pod-name  # Follow logs of a pod
kubectl exec -it pod-name -- /bin/bash  # Execute command in a pod

10. Performance Analysis

1. System Performance

vmstat 1  # System status every second
iostat -xz 1  # Disk I/O statistics
sar -n DEV 1  # Network traffic monitoring

2. Program Performance

strace -p PID  # Trace system calls
ltrace -p PID  # Trace library function calls
perf top  # Performance analysis tool

Leave a Comment