程序员快速参考小手册 更新中 

有的命令一个月可能就用那么几次,不写手册里谁能记得住啊 AI 常用提示词 老师提示词 你现在是老师,教我这个问题。上课战略是“及时反馈,小步快走”。教学过程中注意: 1. 涉及代码、算法、线程、内存或调用链时,生成mermaid图像或者html+js(简单css即可)的互动网页; 2. 不要堆砌术语;让你认为大概率不知道某个术语含义时,先用简单语言解释。 学习路线提示词 请设计一条以“能实际使用”为目标的学习路线。 要求: 按依赖关系排序 区分必须掌握和进阶内容 避免学习低收益知识 每个阶段说明学到什么程度算合格 给出可以验证掌握程度的小项目或练习 不要简单给课程目录。 查漏补缺提示词 我已经学过这个主题。 请不要从头讲教材。 先帮我建立完整知识地图,然后判断: 我必须掌握什么 哪些知识容易漏掉 哪些知识经常被错误理解 哪些知识在实际工作中最重要 哪些属于低优先级细节 帮我找到知识盲区,而不是重复基础内容。 Claude Code # 安装状态栏 npx -y ccstatusline@latest VSCode 解决 code-runner Java Output 乱码 "code-runner.executorMap": { "javascript": "node", "java": "\"C:/Program Files/Java/jdk-17/bin/java.exe\" -Dfile.encoding=UTF-8", Windows 快速完成端口转发 netsh interface portproxy add v4tov4 ` listenaddress=0.0.0.0 ` listenport=2375 ` connectaddress=127.0.0.1 ` connectport=2375 refreshenv Install-Script Refresh-EnvironmentVariables -Force 查端口占用 杀进程 netstat -aon | findstr :8080 taskkill /PID 39656 /F 自定义常用命令别名 notepad $PROFILE function gacp { param ( [string]$msg = "update" ) git add . git commit -m $msg git push } # 删除当前文件夹下空文件夹 function rme { Get-ChildItem -Directory -Recurse | Where-Object { $_.GetFileSystemInfos().Count -eq 0 } | Remove-Item } 文件整理类常用PS脚本 移动子目录所有文件到当前目录 # randomize_filename.ps1 # Rename every file in the current folder to a unique random number (extension preserved). # Usage: place this script in the target folder and run .\randomize_filename.ps1 $currentDir = (Get-Location).Path $scriptPath = $PSCommandPath Write-Host ("Scanning: {0}" -f $currentDir) -ForegroundColor Cyan # Get all files in the current folder, but skip the script itself so we don't rename our own executable. $files = Get-ChildItem -LiteralPath $currentDir -File | Where-Object { $_.FullName -ne $scriptPath } if (-not $files) { Write-Host "No files to rename." -ForegroundColor Yellow return } Write-Host ("Found {0} file(s)" -f $files.Count) # Digit count scales with file count so random collisions stay rare. # Roughly: digits = ceil(log10(N^2)) -> birthday-paradox-safe for typical inputs. $count = $files.Count $digits = [Math]::Max(4, [int][Math]::Ceiling([Math]::Log10($count * $count))) $min = [int][Math]::Pow(10, $digits - 1) $max = [int][Math]::Pow(10, $digits) - 1 Write-Host ("Using {0}-digit numbers ({1}..{2})" -f $digits, $min, $max) # Pre-compute unique new names. The "used" set contains every current name on disk # AND every target name we've already picked, so collisions are impossible by construction. $used = @{} foreach ($file in $files) { $used[$file.Name] = $true } $renameMap = [ordered]@{} foreach ($file in $files) { do { $num = Get-Random -Minimum $min -Maximum ($max + 1) $numStr = $num.ToString().PadLeft($digits, '0') $newName = "$numStr$($file.Extension)" } while ($used.ContainsKey($newName)) $used[$newName] = $true $renameMap[$file.FullName] = $newName } # Apply renames. .NET Move() bypasses PowerShell wildcard parsing (safe for [ ] in names). $renamed = 0 $failed = 0 foreach ($source in $renameMap.Keys) { $newName = $renameMap[$source] $dest = Join-Path $currentDir $newName try { [System.IO.File]::Move($source, $dest) Write-Host (" {0} -> {1}" -f (Split-Path $source -Leaf), $newName) $renamed++ } catch { $failed++ Write-Warning (" Failed: {0} ({1})" -f $source, $_.Exception.Message) } } Write-Host ("`nDone: renamed {0}, failed {1}" -f $renamed, $failed) -ForegroundColor Green 将文件夹下所有文件进行随机重命名(带容灾恢复) # randomize_filename.ps1 # Rename every non-.ps1 file in the current folder to a unique random number (extension preserved). # Maintains restore_filenames.txt so the change is reversible. # Usage: place this script in the target folder and run .\randomize_filename.ps1 $currentDir = (Get-Location).Path $restoreFile = Join-Path $currentDir 'restore_filenames.txt' Write-Host ("Folder: {0}" -f $currentDir) -ForegroundColor Cyan # ----- Restore mode: if a restore map exists, offer to undo first ----- if (Test-Path -LiteralPath $restoreFile) { $answer = Read-Host ("restore_filenames.txt detected. Restore original names? [Y/N]") if ($answer -match '^[Yy]') { $lines = Get-Content -LiteralPath $restoreFile -Encoding UTF8 $restored = 0 $failed = 0 foreach ($line in $lines) { $trimmed = $line.Trim() if (-not $trimmed -or $trimmed.StartsWith('#')) { continue } $parts = $trimmed -split "`t", 2 if ($parts.Count -ne 2) { Write-Warning ("Skipping malformed line: {0}" -f $line) $failed++ continue } $original = $parts[0] $current = $parts[1] $currentPath = Join-Path $currentDir $current $originalPath = Join-Path $currentDir $original if (-not (Test-Path -LiteralPath $currentPath)) { Write-Warning ("Source missing: {0}" -f $currentPath) $failed++ continue } if (Test-Path -LiteralPath $originalPath) { Write-Warning ("Target already exists: {0}" -f $originalPath) $failed++ continue } try { [System.IO.File]::Move($currentPath, $originalPath) Write-Host (" {0} -> {1}" -f $current, $original) $restored++ } catch { Write-Warning ("Failed: {0} ({1})" -f $current, $_.Exception.Message) $failed++ } } if ($failed -eq 0) { Remove-Item -LiteralPath $restoreFile -Force Write-Host ("`nAll {0} file(s) restored. Removed restore_filenames.txt." -f $restored) -ForegroundColor Green } else { Write-Host ("`nPartial restore: {0} succeeded, {1} failed. Keeping restore_filenames.txt." -f $restored, $failed) -ForegroundColor Yellow } return } Write-Host "Proceeding with rename (restore file will be overwritten)." -ForegroundColor Yellow } # ----- Rename mode ----- # Collect files. Skip ALL .ps1 files and the restore file itself. $allFiles = Get-ChildItem -LiteralPath $currentDir -File $files = $allFiles | Where-Object { $_.Extension -ne '.ps1' -and $_.Name -ne 'restore_filenames.txt' } if (-not $files) { Write-Host "No files to rename." -ForegroundColor Yellow return } Write-Host ("Found {0} file(s) to rename (excluded .ps1 and restore_filenames.txt)" -f $files.Count) # Digit count scales with file count so random collisions stay rare. $count = $files.Count $digits = [Math]::Max(4, [int][Math]::Ceiling([Math]::Log10($count * $count))) $min = [int][Math]::Pow(10, $digits - 1) $max = [int][Math]::Pow(10, $digits) - 1 Write-Host ("Using {0}-digit numbers ({1}..{2})" -f $digits, $min, $max) # Pre-compute unique new names. The "used" set includes EVERY name on disk # (including .ps1 files and the restore file, which we are NOT renaming), # plus every target name we pick, so collisions are impossible by construction. $used = @{} foreach ($f in $allFiles) { $used[$f.Name] = $true } $renameMap = [ordered]@{} foreach ($file in $files) { do { $num = Get-Random -Minimum $min -Maximum ($max + 1) $numStr = $num.ToString().PadLeft($digits, '0') $newName = "$numStr$($file.Extension)" } while ($used.ContainsKey($newName)) $used[$newName] = $true $renameMap[$file.FullName] = $newName } # Write restore file BEFORE renaming, so even partial renames leave us with a recoverable map. # Tab-separated: original<TAB>new (filenames only, no paths) $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' $headerLines = @( "# randomize_filename.ps1 restore map" "# created: $timestamp" "# directory: $currentDir" "# format: original`tnew (tab-separated)" "# comment lines starting with '#' are ignored on restore" ) $mappingLines = $renameMap.GetEnumerator() | ForEach-Object { $original = Split-Path $_.Key -Leaf "{0}`t{1}" -f $original, $_.Value } Set-Content -LiteralPath $restoreFile -Value ($headerLines + $mappingLines) -Encoding UTF8 # Apply renames. .NET Move() bypasses PowerShell wildcard parsing (safe for [ ] in names). $renamed = 0 $failed = 0 foreach ($source in $renameMap.Keys) { $newName = $renameMap[$source] $dest = Join-Path $currentDir $newName try { [System.IO.File]::Move($source, $dest) Write-Host (" {0} -> {1}" -f (Split-Path $source -Leaf), $newName) $renamed++ } catch { $failed++ Write-Warning (" Failed: {0} ({1})" -f $source, $_.Exception.Message) } } Write-Host ("`nDone: renamed {0}, failed {1}." -f $renamed, $failed) -ForegroundColor Green Write-Host ("Restore map saved to: {0}" -f $restoreFile) -ForegroundColor Cyan # randomize_filename.ps1 # Rename every non-.ps1 file in the current folder to a unique random number (extension preserved). # Maintains restore_filenames.txt so the change is reversible. # Usage: place this script in the target folder and run .\randomize_filename.ps1 $currentDir = (Get-Location).Path $restoreFile = Join-Path $currentDir 'restore_filenames.txt' Write-Host ("Folder: {0}" -f $currentDir) -ForegroundColor Cyan # ----- Restore mode: if a restore map exists, offer to undo first ----- if (Test-Path -LiteralPath $restoreFile) { $answer = Read-Host ("restore_filenames.txt detected. Restore original names? [Y/N]") if ($answer -match '^[Yy]') { $lines = Get-Content -LiteralPath $restoreFile -Encoding UTF8 $restored = 0 $failed = 0 foreach ($line in $lines) { $trimmed = $line.Trim() if (-not $trimmed -or $trimmed.StartsWith('#')) { continue } $parts = $trimmed -split "`t", 2 if ($parts.Count -ne 2) { Write-Warning ("Skipping malformed line: {0}" -f $line) $failed++ continue } $original = $parts[0] $current = $parts[1] $currentPath = Join-Path $currentDir $current $originalPath = Join-Path $currentDir $original if (-not (Test-Path -LiteralPath $currentPath)) { Write-Warning ("Source missing: {0}" -f $currentPath) $failed++ continue } if (Test-Path -LiteralPath $originalPath) { Write-Warning ("Target already exists: {0}" -f $originalPath) $failed++ continue } try { [System.IO.File]::Move($currentPath, $originalPath) Write-Host (" {0} -> {1}" -f $current, $original) $restored++ } catch { Write-Warning ("Failed: {0} ({1})" -f $current, $_.Exception.Message) $failed++ } } if ($failed -eq 0) { Remove-Item -LiteralPath $restoreFile -Force Write-Host ("`nAll {0} file(s) restored. Removed restore_filenames.txt." -f $restored) -ForegroundColor Green } else { Write-Host ("`nPartial restore: {0} succeeded, {1} failed. Keeping restore_filenames.txt." -f $restored, $failed) -ForegroundColor Yellow } return } Write-Host "Proceeding with rename (restore file will be overwritten)." -ForegroundColor Yellow } # ----- Rename mode ----- # Collect files. Skip ALL .ps1 files and the restore file itself. $allFiles = Get-ChildItem -LiteralPath $currentDir -File $files = $allFiles | Where-Object { $_.Extension -ne '.ps1' -and $_.Name -ne 'restore_filenames.txt' } if (-not $files) { Write-Host "No files to rename." -ForegroundColor Yellow return } Write-Host ("Found {0} file(s) to rename (excluded .ps1 and restore_filenames.txt)" -f $files.Count) # Digit count scales with file count so random collisions stay rare. $count = $files.Count $digits = [Math]::Max(4, [int][Math]::Ceiling([Math]::Log10($count * $count))) $min = [int][Math]::Pow(10, $digits - 1) $max = [int][Math]::Pow(10, $digits) - 1 Write-Host ("Using {0}-digit numbers ({1}..{2})" -f $digits, $min, $max) # Pre-compute unique new names. The "used" set includes EVERY name on disk # (including .ps1 files and the restore file, which we are NOT renaming), # plus every target name we pick, so collisions are impossible by construction. $used = @{} foreach ($f in $allFiles) { $used[$f.Name] = $true } $renameMap = [ordered]@{} foreach ($file in $files) { do { $num = Get-Random -Minimum $min -Maximum ($max + 1) $numStr = $num.ToString().PadLeft($digits, '0') $newName = "$numStr$($file.Extension)" } while ($used.ContainsKey($newName)) $used[$newName] = $true $renameMap[$file.FullName] = $newName } # Write restore file BEFORE renaming, so even partial renames leave us with a recoverable map. # Tab-separated: original<TAB>new (filenames only, no paths) $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' $headerLines = @( "# randomize_filename.ps1 restore map" "# created: $timestamp" "# directory: $currentDir" "# format: original`tnew (tab-separated)" "# comment lines starting with '#' are ignored on restore" ) $mappingLines = $renameMap.GetEnumerator() | ForEach-Object { $original = Split-Path $_.Key -Leaf "{0}`t{1}" -f $original, $_.Value } Set-Content -LiteralPath $restoreFile -Value ($headerLines + $mappingLines) -Encoding UTF8 # Apply renames. .NET Move() bypasses PowerShell wildcard parsing (safe for [ ] in names). $renamed = 0 $failed = 0 foreach ($source in $renameMap.Keys) { $newName = $renameMap[$source] $dest = Join-Path $currentDir $newName try { [System.IO.File]::Move($source, $dest) Write-Host (" {0} -> {1}" -f (Split-Path $source -Leaf), $newName) $renamed++ } catch { $failed++ Write-Warning (" Failed: {0} ({1})" -f $source, $_.Exception.Message) } } Write-Host ("`nDone: renamed {0}, failed {1}." -f $renamed, $failed) -ForegroundColor Green Write-Host ("Restore map saved to: {0}" -f $restoreFile) -ForegroundColor Cyan 清理空文件夹 # clear_empty_folders.ps1 # Delete every empty folder under the current directory. # A folder is "empty" if it contains no files and no subfolders (recursively empty). # Usage: place this script in the target folder and run .\clear_empty_folders.ps1 $currentDir = (Get-Location).Path Write-Host ("Scanning: {0}" -f $currentDir) -ForegroundColor Cyan $removed = 0 do { # -LiteralPath avoids wildcard parsing for paths containing [ ] etc. # -Force includes hidden/system items so truly empty dirs are caught. $emptyDirs = Get-ChildItem -LiteralPath $currentDir -Recurse -Directory | Where-Object { -not (Get-ChildItem -LiteralPath $_.FullName -Force) } if (-not $emptyDirs) { break } foreach ($dir in $emptyDirs) { # Never delete the directory the script is running from if ($dir.FullName -eq $currentDir) { continue } try { # .NET API: deletes only if the folder is actually empty [System.IO.Directory]::Delete($dir.FullName) Write-Host (" Removed: {0}" -f $dir.FullName) $removed++ } catch { Write-Warning ("Failed to remove {0}: {1}" -f $dir.FullName, $_.Exception.Message) } } } while ($true) Write-Host ("`nDone: removed {0} empty folder(s)" -f $removed) -ForegroundColor Green # clear_empty_folders.ps1 # Delete every empty folder under the current directory. # A folder is "empty" if it contains no files and no subfolders (recursively empty). # Usage: place this script in the target folder and run .\clear_empty_folders.ps1 $currentDir = (Get-Location).Path Write-Host ("Scanning: {0}" -f $currentDir) -ForegroundColor Cyan $removed = 0 do { # -LiteralPath avoids wildcard parsing for paths containing [ ] etc. # -Force includes hidden/system items so truly empty dirs are caught. $emptyDirs = Get-ChildItem -LiteralPath $currentDir -Recurse -Directory | Where-Object { -not (Get-ChildItem -LiteralPath $_.FullName -Force) } if (-not $emptyDirs) { break } foreach ($dir in $emptyDirs) { # Never delete the directory the script is running from if ($dir.FullName -eq $currentDir) { continue } try { # .NET API: deletes only if the folder is actually empty [System.IO.Directory]::Delete($dir.FullName) Write-Host (" Removed: {0}" -f $dir.FullName) $removed++ } catch { Write-Warning ("Failed to remove {0}: {1}" -f $dir.FullName, $_.Exception.Message) } } } while ($true) Write-Host ("`nDone: removed {0} empty folder(s)" -f $removed) -ForegroundColor Green ffmpeg 当前文件夹下取出所有mkv视频的中文字幕 Get-ChildItem -File *.mkv | ForEach-Object { $file = $_ $base = [System.IO.Path]::GetFileNameWithoutExtension($file.Name) $tracks = ffprobe -v error ` -select_streams s ` -show_entries stream=index:stream_tags=language ` -of json ` "$($file.FullName)" | ConvertFrom-Json $chineseTracks = $tracks.streams | Where-Object { $_.tags.language -match '^(zh|zho|chi|zh-cn|zh-hans|zh-tw|zh-hant)$' } $n = 1 foreach ($track in $chineseTracks) { $output = "$base.zh.$n.srt" Write-Host "提取: $($file.Name) -> $output" ffmpeg -y ` -i "$($file.FullName)" ` -map "0:$($track.index)" ` "$output" $n++ } } Linux Linux开辟虚拟内存(Swap) free -h Linux实现FRP内网穿透 的是让国内用户能连到一台没有公网 IP 的家庭电脑——用的是反向内网穿透: ...

2025-08-24 10:51:14 PM · 18 分钟
工具手册