用阿里的99计划租了台服务器练手,没有安装面板。让ChatGPT弄了个命令行的cheat sheet,转载如下(尚未测试):
Here’s a concise Linux SSH Command Line Cheat Sheet to get you started:
Basic SSH Commands
1. Connect to a server:
ssh username@hostname_or_IP
Example:
ssh user@192.168.1.1
2. Copy files from local to server:
scp local_file_path username@hostname_or_IP:/remote/path
Example:
scp file.txt user@192.168.1.1:/home/user/
3. Copy files from server to local:
scp username@hostname_or_IP:/remote/path local_file_path
Example:
scp user@192.168.1.1:/home/user/file.txt
.
4. Exit SSH session:
exit
File Management
1. List files and directories:
ls
ls -l # Detailed list
ls -a # Include hidden files
2. Navigate directories:
cd /path/to/directory
cd .. # Go up one level
cd ~ # Go to home directory
3. Create a file:
touch filename
4. View file content:
cat filename
less filename # Scroll through the file
5. Create a directory:
mkdir directory_name
6. Delete a file or directory:
rm filename
rm -r directory_name # Recursively delete a directory
Permissions
1. Change file permissions:
chmod 755 filename
2. Change file owner:
chown new_owner filename
Process and System Management
1. Check disk usage:
df -h
2. Check memory usage:
free -h
3. View running processes:
ps aux
4. Kill a process:
kill PID
Replace PID with the Process ID from ps aux.
5. Reboot server:
sudo reboot
Networking
1. Check network connection:
ping hostname_or_IP
2. Check active network connections:
netstat -tuln
Package Management (CentOS – yum or dnf)
1. Install a package:
sudo yum install package_name
2. Update all packages:
sudo yum update
3. Search for a package:
yum search package_name
4. Remove a package:
sudo yum remove package_name
Helpful Commands
1. Show current directory:
pwd
2. Check system info:
uname -a
3. Check free disk space:
du -sh /path
4. Check uptime:
uptime
5. Search for a file:
find / -name "filename"
Tips
• Use Tab for autocompletion of commands and filenames.
• Use Ctrl+C to cancel a running command.
• Use Ctrl+R to search your command history.