Table of contents
进程管理
ps aux | grep NAME
ps -ef
pstree
pgrep -a NAME
top # 进去之后按/搜索
htop # 进去之后按F3搜索
kill PID #SIGTERM 15 礼貌地请进程退出
kill -9 PID #SIGKILL 9 强制关闭
pkill NAME
硬盘与存储
# 查看信息
df -h
du -sh *
du -sh /folder
du -h --max-depth=1 | sort -hr
lsblk
sudo fdisk -l
# 挂载
lsblk -f
sudo mkdir -p /mnt/usb_disk
sudo mount -t ntfs-3g /dev/sdX1 /mnt/usb_disk
# or sudo mount -t exfat /dev/sdX1 /mnt/usb_disk
sudo umount /mnt/usb_disk
日常杂项
# 打包并压缩(tar.gz)
tar -czvf archive.tar.gz /path/to/dir
# 解压 tar.gz
tar -xzvf archive.tar.gz
# 压缩目录(必须用 -r)
zip -r archive.zip /path/to/directory
# 解压到当前目录
unzip archive.zip
scp -r user@remote_ip:/home/user/my_folder ./
sudo powertop
watch nvidia-smi
# 秒数 -n 1
# 高亮变化 -d
# 不显示标题 -t
pwd #print working directory 打印当前目录
wget -c https://demo #断点续传 指定目录 -P /mnt/disk1/a/aa
ln -s /path/to/target link_name #软链接
fc-cache -fv #刷新字体设置
git
git init # 在当前目录初始化一个新的 Git 仓库(生成 .git 目录)
git clone <url> # 克隆远程仓库到本地
git config --global user.name "你的名字" # 配置提交者姓名
git config --global user.email "你的邮箱" # 配置提交者邮箱
git status # 查看当前工作区状态(哪些文件修改了但未暂存)
git add <file> # 将文件添加到暂存区
git add . # 将所有修改添加到暂存区
git commit -m "提交信息" # 将暂存区内容提交到本地仓库
git commit --amend # 修改上一次提交(原理:产生一个新的 commit 对象替换旧的)
git branch # 列出所有本地分支
git branch <name> # 创建新分支
git checkout <name> # 切换到指定分支(现代做法使用 git switch <name>)
git checkout -b <name> # 创建并切换到新分支
git merge <name> # 将指定分支合并到当前分支
git branch -d <name> # 删除已合并的分支
git remote add origin https://github.com/用户名/仓库名.git # 添加远程映射
git remote -v # 查看远程仓库地址
git fetch # 拉取远程更新但不合并
git pull # 拉取远程更新并尝试自动合并(等于 fetch + merge)
git push origin <branch> # 将本地分支推送到远程
SSH
服务器免密登录
ssh-keygen -t ed25519 #-f 指定名字,也可以直接生成,后续可以指定
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@你的服务器IP
本地编辑 ~/.ssh/config
Host myvps
HostName
User root
IdentityFile ~/.ssh/id_ed25519
tmux
tmux new -s demo # 新建
tmux ls # 列表
exit # 退出 或 Ctrl+b 再 d
tmux attach -t demo # 接回
# 关闭 Ctrl+b 再 x
Python环境
Huggingface
export HF_ENDPOINT=https://hf-mirror.com
Autodl
apt update && apt install tmux
source /etc/network_turbo
# 下载并解压
wget https://github.com/ox01024/cmirror/releases/latest/download/cmirror-linux-x64.tar.gz
tar -xzf cmirror-linux-x64.tar.gz
# 添加执行权限
chmod +x cmirror
# 移动到系统路径(可选)
sudo mv cmirror /usr/local/bin/
# 验证安装
cmirror --help
unset http_proxy && unset https_proxy
cmirror use pip --fastest
cmirror use conda --fastest