标签搜索

命令行常用命令

wxb
wxb
2026-04-08 / 0 评论 / 2 阅读 / 正在检测是否收录...

通用命令

环境命令
venv
pip list  列出所有包及版本
pip freeze > requirements.txt 生成 requirements 格式
pip list --format=freeze | grep -v "@ file" > requirements.txt  若有些包是从本地安装的
python -m venv .venv          # 1. 创建环境
source .venv/bin/activate     # 2. 激活 (Linux/macOS)
# .venv\Scripts\activate      # 2. 激活 (Windows)
pip install -r requirements.txt  # 3. 安装依赖
conda
conda list
conda env export > environment.yml
conda env export --no-builds > environment.yml 导出时去掉构建哈希
conda create --name myenv --file requirements.txt
conda create --name myenv python=3.9   # 1. 创建环境
conda activate myenv                   # 2. 激活
pip install -r requirements.txt        # 3. 用 pip 安装依赖
docker
docker exec my_container pip freeze > requirements.txt  假设容器名为 my_container 从容器中导出
COPY requirements.txt 最佳实践 – 在 Dockerfile 中声明依赖
git命令
…or create a new repository on the command line
echo "# xb-CLI" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:No-neck-King/xb-CLI.git
git push -u origin main
======================================================================
…or push an existing repository from the command line
git remote add origin git@github.com:No-neck-King/xb-CLI.git
git branch -M main
git push -u origin main
======================================================================
                  配置
git config --global user.name "Your Name"   # 设置用户名
git config --global user.email "email@example.com"  # 设置邮箱
git config --list               # 查看所有配置
              仓库初始化与克隆
git init                        # 初始化新仓库
git clone <url>                 # 克隆远程仓库
git clone -b <branch> <url>     # 克隆指定分支
         基本操作(添加、提交、状态、日志)
git status                      # 查看工作区状态
git add <file>                  # 添加文件到暂存区
git add .                       # 添加所有修改
git commit -m "message"         # 提交暂存区内容
git log                         # 查看提交历史
git log --oneline --graph       # 简洁图形化日志
git diff                        # 查看未暂存的改动
git diff --staged               # 查看已暂存但未提交的改动
                  远程仓库
git remote -v                   # 查看远程仓库地址
git remote add origin <url>     # 添加远程仓库
git push origin <branch>        # 推送分支到远程
git push -u origin <branch>     # 推送并设置上游
git pull                        # 拉取并合并远程分支(fetch + merge)
git fetch                       # 仅拉取远程更新,不合并
git clone --depth 1 <url>       # 浅克隆(只获取最新提交)
# 忽略所有 .log 文件
*.log

# 忽略 build 目录(及其中所有内容)
build/

# 忽略特定文件
config.local.ini

# 取反(不忽略特定文件)
!important.log

# 忽略根目录下的 tmp 文件
/tmp

ubuntu

bash

#当前目录下的所有文件中搜索包含“关键词”的行
grep "关键词" *
#递归子目录文件搜索   r==--recursive
grep -r "关键词" .
#lsof 命令用于列出当前系统打开文件的工具  网络连接也可以看作是文件
sudo lsof -i -P -n
-i 表示显示网络连接信息
-P 表示直接显示IP地址,不使用域名解析
-n 表示不使用域名解析,与 lsof -i -P 效果相同,但更清晰
#结合find  搜索所有.py文件中的“关键词”
find . -name "*.py" -exec grep "关键词" {} +
  • 常用命令

    #目录操作
    pwd ls  cd <dir>   mkdir     rmdir <dir> 
    #文件操作
    cp mv rm cat less 
    #文本处理
    grep <pattern> <file>    find <path> -name <name>   
    #权限/进程
    chmod <mod> <file>  chown <user>:<group> <file>  ps aux 进程列表  kill <pid>
    #网络/系统
    ifconfig/ip addr   ping <host>   ssh <user>@<host>   scp  <src><dst>  
    df -h    free -h   sudo <cmd>    apt   

    vim & nano

windows

powershell

Get-ChildItem -Recurse | Select-String "关键词"
递归清空pycache
Get-ChildItem -Path . -Filter "__pycache__" -Directory -Recurse | Remove-Item -Recurse -Force

命令说明:

  • Get-ChildItem -Recurse:获取当前目录及其子目录下的所有文件。
  • Select-String "关键词":在这些文件中搜索指定的关键词。

‌Get-ChildItem‌ 是 PowerShell 中用于获取指定路径下文件和文件夹(即“子项”)的核心命令,功能类似于 CMD 中的 dir 或 Linux 中的 ls

#仅返回文件夹或文件
Get-ChildItem -Directory
Get-ChildItem -File      
#‌查找特定类型文件
Get-ChildItem -Path "C:\Logs" -Filter "*.log" -Recurse
Get-ChildItem -Recurse | Select-String "关键词"

cmd

findstr /s /i "关键词" *.*

命令说明:

  • /s:表示搜索当前目录及所有子目录(即递归搜索)。
  • /i:表示在搜索时忽略大小写。如果希望严格区分大小写,可以去掉这个参数。
  • "关键词":替换为你要搜索的具体文字。
  • .:表示搜索所有类型的文件。你也可以指定特定类型的文件,例如 *.js 只搜索JavaScript文件。
0

评论 (0)

取消