命令行速查手册
命令行速查手册
Section titled “命令行速查手册”日常开发中常用的命令速查,涵盖 APT、Docker、Git、Windows、Node.js 等。
APT 包管理
Section titled “APT 包管理”GPG 公钥问题
Section titled “GPG 公钥问题”在 apt-get update 时遇到 NO_PUBKEY 错误:
W: GPG error: http://ppa.launchpad.net karmic Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D45DF2E8FC91AE7E解决办法:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D45DF2E8FC91AE7EDocker 中清理 APT 缓存
Section titled “Docker 中清理 APT 缓存”在 Docker Ubuntu 镜像中安装软件后,清理缓存以减小镜像体积:
apt-get clean autocleanapt-get autoremove --yesrm -rf /var/lib/{apt,dpkg,cache,log}/Docker
Section titled “Docker”获取容器内 IP 地址
Section titled “获取容器内 IP 地址”Docker 基础镜像通常不包含 ifconfig,可用以下命令获取 IP:
hostname -iDocker in Docker
Section titled “Docker in Docker”在容器中运行 Docker,挂载宿主机的 docker.sock:
docker run -v /var/run/docker.sock:/var/run/docker.sock -ti dockerDocker 资源清理
Section titled “Docker 资源清理”# 删除所有悬空(dangling)镜像docker image prune -f
# 删除所有未被容器引用的镜像docker image prune -a
# 强制删除所有未使用的镜像docker rmi $(docker images -q)
# 清理整个 Docker 所有资源(镜像、容器、网络)docker system prune -a -f
# 清理不再使用的 Volumedocker system prune --volumes -f用户名和邮箱设置
Section titled “用户名和邮箱设置”Git 提供三级配置,优先级:项目级 > 全局 > 系统
# 项目级别(存储在 .git/config)git config user.name "Your project specific name"
# 全局级别(存储在 ~/.gitconfig)git config --global user.name "Your Name"
# 系统级别(存储在 /etc/gitconfig)git config --system user.name "Your default name"中文乱码问题
Section titled “中文乱码问题”git status 显示中文为八进制编码:
git config --global core.quotepath false批量修改提交的用户名和邮箱
Section titled “批量修改提交的用户名和邮箱”使用脚本 fix-git-username-email.sh:
./fix-git-username-email.sh \ --unexpected-username "old-name" \ --expected-username "new-name" \Windows
Section titled “Windows”激活自带图片查看器
Section titled “激活自带图片查看器”将以下内容保存为 .reg 文件并运行:
Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations]".tif"="PhotoViewer.FileAssoc.Tiff"".tiff"="PhotoViewer.FileAssoc.Tiff"".jpg"="PhotoViewer.FileAssoc.Tiff"".png"="PhotoViewer.FileAssoc.Tiff"".gif"="PhotoViewer.FileAssoc.Tiff"Node.js
Section titled “Node.js”rimraf:跨平台的 rm -rf
Section titled “rimraf:跨平台的 rm -rf”Windows 和 Unix 的 rm 命令有差异,rimraf 提供跨平台支持:
{ "scripts": { "clean": "rimraf lib-es5" }}