Linux 命令速查
适用平台:Linux (Ubuntu / CentOS 等) / macOS / WSL。
1. 目录与文件操作
1 2 3 4 5 6
| pwd ls -lah mkdir -p /path/to/dir rm -rf mydir/ cp -r src_dir dest_dir mv oldname newname
|
2. 文件查看与文本搜索
1 2 3 4 5 6
| cat file.txt less file.txt head -n 20 file.txt tail -f app.log grep -rn "keyword" ./ find /path -name "*.py"
|
3. 实验进程与系统监控
1 2 3 4 5 6 7
| nvidia-smi watch -n 1 nvidia-smi top free -h df -h ps aux | grep python kill -9 <PID>
|
后台跑实验常用(防止断网或关掉终端导致任务中断):
1 2 3 4 5 6 7
| nohup python train.py > output.log 2>&1 & tail -f output.log jobs
tmux new -s myexp tmux attach -t myexp
|
4. 远程连接与网络排错
1 2 3 4 5
| ssh user@ip_address scp file.zip user@ip:/path/ scp user@ip:/path/file ./ ping github.com netstat -tuln
|
GitHub SSH 连接超时 (Port 22 Timeout) 变通方案:
如果在某些网络环境下 22 端口被屏蔽导致无法拉取代码,可通过 443 端口复用 SSH。在 ~/.ssh/config 文件中追加以下配置:
1 2 3 4
| Host github.com Hostname ssh.github.com Port 443 User git
|
配置完成后,可通过以下命令测试连接是否恢复正常:
5. 权限与打包解压
1 2 3 4 5 6 7 8 9 10 11 12
| chmod +x script.sh chmod 755 -R mydir/ chown -R user:group mydir/
tar -czvf archive.tar.gz dir/ tar -xzvf archive.tar.gz
zip -r data.zip dir/ unzip data.zip -d /dest/
|