PowerShell
计算文件的哈希
支持的哈希函数: MD5
SHA1
SHA256
SHA384
SHA512
Get-FileHash -Algorithm MD5 -Path .\filename.txt | Select-Object Hash
字符串对比
Compare-Object -CaseSensitive "ABC" "abc"
类似 tail -f
监控文件变化并输出
Get-Content -Path "filename.txt" -Wait
修改 JAVA_HOME
变量
param($s)
# "Give permissions to HKLM\System\CurrentControlSet\Control\Session Manager\Environment to a desired user"
# [System.Environment]::SetEnvironmentvariable("JAVA_HOME", "C:\Program Files\Java\jdk-11.0.10", "Machine")
if ($s -eq 11) {
[environment]::SetEnvironmentvariable('JAVA_HOME', 'C:\Program Files\Java\jdk-11.0.10', 'Machine')
}
if ($s -eq 8) {
[environment]::SetEnvironmentvariable('JAVA_HOME', 'C:\Program Files\Java\jdk1.8.0_261', 'Machine')
}
[System.Environment]::GetEnvironmentvariable("JAVA_HOME", "Machine")
生成 UUID
[System.Guid]::NewGuid().toString()
# [System.Guid]::NewGuid().toString("B")
# [System.Guid]::NewGuid().toString("B").toLower()
# [System.Guid]::NewGuid().toString("B").toUpper()
查询所有 WIFI
信息密码
# 查询所有wifi名称
netsh wlan show profiles | Where-Object {$_ -match 'All User Profile'}
# 查询指定wifi的密码
netsh wlan show profile name="WIFI_NAME" key=clear | Where-Object {$_ -match 'Key Content'}
禁用 Ctrl
+ Space
切换输入法
将脚本改文件后缀为reg并双击导入
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000010]
"Key Modifiers"=hex:00,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:ff,00,00,00
[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000070]
"Key Modifiers"=hex:00,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:ff,00,00,00
[HKEY_USERS\.DEFAULT\Control Panel\Input Method\Hot Keys\00000010]
"Key Modifiers"=hex:00,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:ff,00,00,00
[HKEY_USERS\.DEFAULT\Control Panel\Input Method\Hot Keys\00000070]
"Key Modifiers"=hex:00,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:ff,00,00,00
aria2.conf
更新 bt-tracker
$ConfigFile = "C:\aria2-1.35.0-win-64bit-build1\aria2_auto_update.conf"
$TrackersFile = "trackers_best.txt"
$DownloadLink = "https://raw.githubusercontent.com/ngosang/trackerslist/master/$TrackersFile"
Invoke-WebRequest -Uri $DownloadLink -OutFile $env:TEMP\$TrackersFile
$TrackersStream = (Get-Content $env:TEMP\$TrackersFile -Raw).Replace("`n`n", ",").Insert(0, "bt-tracker=")
$TrackersStream = $TrackersStream.Substring(0, $TrackersStream.Length - 1)
$ExcludeLineNum=(Select-String -Path $ConfigFile -SimpleMatch "bt-tracker=").LineNumber
$ConfigStream = Get-Content $ConfigFile -Encoding UTF8
$ConfigStream[$ExcludeLineNum-1]=$TrackersStream
Set-Content -Path $ConfigFile -Value $ConfigStream -Encoding UTF8
Remove-Item -Path $env:TEMP\trackers*
安装 Firefox
# 下载最新版Firefox
Invoke-WebRequest -o ./ff-installer.exe 'https://download.mozilla.org/?product=firefox-latest&os=win64&lang=zh-CN'
# 安装
./ff-installer.exe
查询天气
curl wttr.in
Bash
查询目录和文件
find
命令
基本使用
# find 路径 参数
# "." 代表当前目录
# "-type f" 代表要查找的是普通文件
# "-name '*.out'" 代表按文件名称查找, 且是以".out"结尾的文件
find . -type f -name '*.out'
常用命令
参数 | 解释 | 示例 |
---|---|---|
-exec | 对匹配的文件执行该参数所给出的其他linux命令 | 查找当前目录下所有.txt文件并拼接写入到all.txt文件find . -type f -name "*.txt" -exec cat {} \;> /all.txt |
-ok | 同 -exec , 在执行命令前会确认 | |
-type | 查找某一类型的文件 | b - 块设备文件; d - 目录; c - 字符设备文件; p - 管道文件;l - 符号链接文件; f - 普通文件; s - socket文件 |
-name | 按文件名称查找 | |
-perm | 按文件权限查找 | |
-mtime | -mtime -n +n 按更改时间查找 -n表示距现在n天以内 +n表示距现在n天以前 | 最后访问时间: -atime (天) -amin (分)最后修改时间: -mtime (天) -mmin (分)数据元(权限等)最后修改时间: -ctime (天) -cmin(分) |
压缩/解压
tar
命令
基本使用
# 压缩为*.tar.gz
tar -zcvf foldername.tar.gz ./foldername
# *.tar.gz解压缩
tar -zxvf foldername.tar.gz
命令详细解释
参数 | 解释 |
---|---|
-z | filter the archive through gzip |
-c --create | create a new archive |
-x --extract --get | extract files from an archive |
-v --verbose | verbosely list files processed |
-f --file | use archive file or device ARCHIVE |
-r --append | append files to the end of an archive |
-t --list | list the contents of an archive |
aria2
更新 bt-tracker
#!/bin/bash
list=`wget -qO- https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt|awk NF|sed ":a;N;s/\n/,/g;ta"`
if [ -z "`grep "bt-tracker" /conf/aria2.conf`" ]; then
sed -i '$a bt-tracker='${list} /conf/aria2.conf
else
sed -i "s@bt-tracker.*@bt-tracker=$list@g" /conf/aria2.conf
fi