首页  编辑  

Doskey命令别名

Tags: /计算机文档/DOS应用技巧/   Date Created:

如何给命令提示符设置别名

http://superuser.com/questions/49170/create-an-alias-in-windows-xp

利用doskey完成,例如:

doskey d=dir $*

如果要永久起作用,可以利用一个alias命令文件,修改注册表:

reg add "hkcu\software\microsoft\Command Processor" /v Autorun /t reg_sz /d "DOSKEY /macrofile=D:\Tools\doskey-macros.txt"

然后把所有的别名命令放在D:\Tools\doskey-macros.txt中,启动cmd会自动加载这个文件。

其中D:\Tools\doskey-macros.txt内容类似下面:

vi="C:\Program Files\Notepad++\notepad++.exe" $*

ls=dir /w $*

ll=dir /a $*

bash="C:\Program Files\Git\git-bash.exe" 

~=pushd %UserProfile%

desk=cd %UserProfile%\Desktop

pwd=cd

macros=doskey /macros

kill=taskkill /f /im:$*

up=systeminfo | find "启动时间"

uptime=@for /f "tokens=2 delims==" %G in ('wmic os get LocalDateTime /value') do @echo %G

cat=type $*

gc=git clone $*

..=cd ..

...=cd ..\..

....=cd ..\..\..

post=curl --ssl-no-revoke -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" -e "$1" -H "X-Requested-With: XMLHttpRequest" -F "file=@$2" $1 $3 $4 $5 $6 $7 $8 $9

wgeta=wget -r -p -np -k -b -t 3 -c -T 30 $*

reload=doskey /macrofile=D:\Tools\doskey-macros.txt

rm=del $*

when=wmic process get processid,caption,creationdate | findstr /c:CreationDate /c:$*

cd-=popd

nl=netstat -nao | find "LISTEN"

ip=ipconfig /all | find "IPv4 地址"

dns=ipconfig /all | find "DNS 服务器"

http=curl --ssl-no-revoke -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" $*

sudo=nsudo -P:E -U:S $*

bs=backstab -n $1 -k
wql=powershell -command "Get-WmiObject -query '$*'"
wmi=powershell -command "Get-WmiObject -Namespace 'root\WMI' -Query '$*'"
kt="..\..\bin\keytool.exe" -import -file "$1" -keystore cacerts -storepass changeit
kafka=kafka-console-producer.bat --broker-list localhost:9092 --topic $*
kafkaclean=echo {"partitions":[{"topic":"$1", "partition":0, "offset":-1}]}>%temp%\kf_clean.json && kafka-delete-records.bat --bootstrap-server localhost:9092 --offset-json-file %temp%\kf_clean.json && del %temp%\kf_clean.json
gitpath=set path=%path%;C:\Program Files\Git\usr\bin
res=wmic path Win32_VideoController get CurrentHorizontalResolution, CurrentVerticalResolution, CurrentBitsPerPixel
class=powershell -command "Get-WmiObject -Namespace 'root\$1' -List | Select-Object -ExpandProperty Name"
ps=powershell -command "$*"
env=rundll32.exe sysdm.cpl,EditEnvironmentVariables

最好不要直接把 AutoRun设置为Bat或者Cmd文件,因为这样,在某些程序,如Jetbrains IDEA,VS Code或第三方调用Cmd的程序,启动的时候,不一定会正确切换到 Working Directory(工作目录),例如正常情况下 Idea 打开命令提示符终端,会自动切换到 $PROJECT_DIR$ 目录,但是如果设置 AutoRun 为批处理文件后,会导致这个目录切换失败。