欢迎来到海上华帆的博客园子

记录一些学习过程中的心得体会,供自己和有缘人参考!

常用长命令

powershell 删除 Django 项目的迁移文件

删除 migrations目录下 除了__init__.py文件以外的其他 *.py文件

Get-ChildItem -Path . -Recurse -Include "*.py" -File | Where-Object { $_.DirectoryName.EndsWith("migrations") -and $_.Name -ne "__init__.py" -and $_.FullName -notmatch "\\env\\" -and $_.FullName -notmatch "\\venv\\" -and $_.FullName -notmatch "\\site-packages\\" } | Remove-Item -Force

删除__pycache__目录及目录下的所有文件

Get-ChildItem -Path . -Recurse -Directory -Filter "__pycache__" | Where-Object { $_.FullName -notmatch "\\env\\" -and $_.FullName -notmatch "\\venv\\" -and $_.FullName -notmatch "\\site-packages\\" } | Remove-Item -Recurse -Force

PowerShell 删除当前目录下所有 SQLite3 数据库文件

# 删除当前目录及其子目录中的所有 .sqlite3 和 .db 文件(SQLite常用扩展名)
rm *.sqlite3
rm *.db

常用命令

Get-ChildItem -Path . -Directory -Filter "__pycache__" | Where-Object { $_.FullName -notmatch "\\env\\" -and $_.FullName -notmatch "\\venv\\" -and $_.FullName -notmatch "\\site-packages\\" } | Remove-Item -Recurse -Force
Get-ChildItem -Path . -Include "*.py" -File | Where-Object { $_.DirectoryName.EndsWith("migrations") -and $_.Name -ne "__init__.py" -and $_.FullName -notmatch "\\env\\" -and $_.FullName -notmatch "\\venv\\" -and $_.FullName -notmatch "\\site-packages\\" } | Remove-Item -Recurse -Force
rm *.sqlite3                                                                           
python manage.py makemigrations && python manage.py migrate  

Linux / Mac OS 删除 Django 项目的迁移文件

删除 migrations目录下 除了__init__.py文件以外的其他 *.py文件

find . -path "*/migrations/*.py" -not -name "__init__.py" -not -path "*env*" -not -path "*venv*" -not -path "*site-packages*" -delete

删除__pycache__目录及目录下的所有文件

find . -type d -name "__pycache__" -not -path "*env*" -not -path "*venv*" -not -path "*site-packages*" -exec rm -rf {} +

Linux 删除当前目录下所有 SQLite3 数据库文件

rm -f *.sqlite3

如果需要同时删除 -journal 文件

find . -type f -name "*-journal" -delete

### 常用命令
```shell
find . -path "*/migrations/*.py" -not -name "__init__.py" -not -path "*env*" -not -path "*site-packages*" -delete
find . -type d -name "__pycache__" -not -path "*env*" -not -path "*venv*" -not -path "*site-packages*" -exec rm -rf {} +                  
rm *.sqlite3
python manage.py makemigrations && python manage.py migrate

删除python缓存文件

Get-ChildItem -Recurse -Include *.pyc,__pycache__ | Remove-Item -Recurse -Force
posted @ 2025-06-25 09:29  海上华帆  阅读(16)  评论(0)    收藏  举报