个人使用的一些脚本命令

来源自我的博客

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
命令详细解释
参数解释
-zfilter the archive through gzip
-c --createcreate a new archive
-x --extract --getextract files from an archive
-v --verboseverbosely list files processed
-f --fileuse archive file or device ARCHIVE
-r --appendappend files to the end of an archive
-t --listlist 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值