是否有命令在Windows中获取cmd命令列表?


Answers:


20

有关命令列表:

help

有关特定命令的详细信息:

help <command>

要么

<command> /?

例如:

help xcopy
xcopy /?

太好了!非常有用的命令。谢谢
amiregelz

您可以使用 xcopy /? 获取有关命令的信息。 :)
avirk

是否有可能获得一个网络命令列表,如 pingarpnslookup?看起来 help 仅生成基本Windows命令列表,而不生成网络命令。
amiregelz

2
@amiregelz:那些是节目中的节目 windows\system32 我相信它在解析程序/命令时看起来的文件夹。对于你的清单,你可以在那里寻找exes。见奥利弗的回答。
George Duckett

14

你可以在这里找到官方列表 Microsoft命令行参考A-Z 。除此之外...

为了直接回答你的问题,我设计了一个简单列出所有内容的脚本 .exe 你可以执行的文件(因为它们位于你的文件中) PATH )。默认情况下,它仅列出也位于其中的那些 %WINDIR% (除非你用它来运行它 --all )。

在脚本的前一次迭代中,我用每个命令启动 /?,这是一个非常糟糕的主意。不是每个应用程序都在 PATH 理解那个参数。有些只是启动并继续运行,而不是打印任何帮助。因此,很快就会占用大量资源。

@SETLOCAL ENABLEEXTENSIONS 
@ECHO OFF

IF "%1"=="--all" (
    SET LIST_ALL=TRUE
)
CALL :printPath "%PATH%"
:printPath
FOR /F "tokens=1,* delims=;" %%A IN ("%~1") DO (
    IF EXIST "%%A" (
        PUSHD "%%A"
        FOR %%F IN (*.exe) DO (
            ECHO.%%~dnpfF | FINDSTR /C:"%WINDIR%" 1> NUL
            IF ERRORLEVEL 1 (
                IF "%LIST_ALL%"=="TRUE" ECHO.%%~dnpfF
            ) ELSE (
                ECHO.%%~dnpfF
            )
        )
        POPD
    ) ELSE (
        REM ECHO Skipping non-existent folder '%%A'
    )
    CALL :printPath "%%~B"
)
ENDLOCAL

所以,那里。这将为您提供所有可用命令及其参数的列表。正如你已经可以预料的那样,它没有人们想象的那么有用。

这才是真正重要的!

比这更有趣 .exe 你的文件 PATH 是的 cmd.exe 内置插件。喜欢 IFFORSET。我没有内置插件的完整列表,但您可以通过运行查看大部分内置插件 cmd.exe /?

DEL or ERASE
COLOR
CD or CHDIR
MD or MKDIR
PROMPT
PUSHD
POPD
SET
SETLOCAL
ENDLOCAL
IF
FOR
CALL
SHIFT
GOTO
START (also includes changes to external command invocation)
ASSOC
FTYPE

虽然,在那时帮助是参考 命令扩展 ,因此列表可能不完整。让我们仔细看看一些内置插件:

FOR /?

的文档 FOR 命令列出了您可以传递给的所有疯狂参数 FOR。如果您想要编写与之相关的任何内容,这是首选实用程序 循环

该文档还包含疯狂的“波浪符号”的解释:

In addition, substitution of FOR variable references has been enhanced
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

IF /?

IF 是命令 分枝 。您需要此页面,因为它列出了比较运算符:

If Command Extensions are enabled IF changes as follows:

    IF [/I] string1 compare-op string2 command
    IF CMDEXTVERSION number command
    IF DEFINED variable command

where compare-op may be one of:

    EQU - equal
    NEQ - not equal
    LSS - less than
    LEQ - less than or equal
    GTR - greater than
    GEQ - greater than or equal

SET /?

SET 允许您对变量执行各种操作。

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.  The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

    ()                  - grouping
    ! ~ -               - unary operators
    * / %               - arithmetic operators
    + -                 - arithmetic operators
    << >>               - logical shift
    &                   - bitwise and
    ^                   - bitwise exclusive or
    |                   - bitwise or
    = *= /= %= += -=    - assignment
      &= ^= |= <<= >>=
    ,                   - expression separator

它还允许通过上面提到的“波浪符号”进行字符串操作


你认为有办法获得列出的命令吗? 这里 但不是在打字时 help?例如网络命令 ipconfignslookuparptelnetping
amiregelz

@amiregelz:应该可以正常工作 C:\Windows\System32。我认为那是在 PATH
Der Hochstapler

即使它们位于那里,它也不会列出它们。它列出了 ARP.EXE 虽然。你看到执行脚本时我提到的命令了吗?
amiregelz

@amiregelz:是的,但我觉得如果你的话有问题 PATH 包含不再存在的文件夹。这会导致脚本中断。也许这就是问题?我正在努力修复。
Der Hochstapler

2
@amiregelz:似乎开始并不是那么明智 一切 申请你的 PATH :d
Der Hochstapler

6

dostips.com上有批处理脚本( CreateDosCommandIndex.bat )生成一个html文件,其中包含系统上可用dos命令的完整列表,以及通过“commandname /?”生成的相应输出

我在下面报告它,因为dostips.com目前似乎有数据库负载相关的问题,他们的网站间歇性地工作。

@ECHO OFF
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS

REM --
REM -- Copyright note
REM -- This script is provided as is.  No waranty is made, whatso ever.
REM -- You may use and modify the script as you like, but keep the version history with
REM -- recognition to http://www.dostips.com in it.
REM --

REM Version History:
REM         XX.XXX      YYYYMMDD Author Description
SET "version=01.000"  &:20051201 p.h.   initial version, origin http://www.dostips.com
SET "version=01.001"  &:20060122 p.h.   Fix missing exclamation marks in documentation (http://www.dostips.com)
SET "version=01.002"  &:20060218 p.h.   replaced TEXTAREA with PRE XMP (http://www.dostips.com)
SET "version=01.003"  &:20060218 p.h.   php embedding (http://www.dostips.com)
SET "version=01.004"  &:20060723 p.h.   fix page links for FireFox (http://www.dostips.com)
SET "version=01.005"  &:20061015 p.h.   invoke HELP via '"call" help', allows overriding help command with a help.bat file (http://www.dostips.com)
SET "version=01.006"  &:20061015 p.h.   cleanup progress indicator (http://www.dostips.com)
SET "version=01.007"  &:20080316 p.h.   use codepage 1252 to support european users (http://www.dostips.com)
SET "version=02.000"  &:20080316 p.h.   use FOR command to generate HTML, avoids most escape characters (http://www.dostips.com)
SET "version=02.000"  &:20100201 p.h.   now using css and xhtml
REM !! For a new version entry, copy the last entry down and modify Date, Author and Description
SET "version=%version: =%"

for /f "delims=: tokens=2" %%a in ('chcp') do set "restore_codepage=%%a"
chcp 1252>NUL

set "z=%~dpn0.htm"

rem echo.^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"^> >"%z%"
echo.^<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"^> >"%z%"

set "title=DOS Command Index"
for /f "tokens=*" %%a in ('ver') do set "winver=%%a"

echo.Creating the header ...
for %%A in (
            "<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>"
            "<head>"
            "<style type='text/css'>"
            "  h1              {text-align:center;}"
            "  h2              {text-align:center;}"
            "  table.center    {margin-left: auto;margin-right: auto;}"
            "  td              {text-align:left;}"
            "  div.center      {text-align:center;}"
            "  div.sourcebatch {background: #DDDDDD;}"
            "  div.helptext    {background: #F8F8FF;}"
            "  div.top         {float: right;}"
            "</style>"
            "<title>%title%</title>"
            "<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />"
            "</head>"
            "<body bgcolor='#FFFFCC'>"
            "<font color='darkblue'>"
            "<h1>%title%</h1>"
            "<div class='center'>"
            "<table class='center' border='1' cellspacing='1' cellpadding='3'>"
            "    <tr><td>Windows Version</td><td>:</td><td>%winver%</td></tr>"
            "    <tr><td>Document Source</td><td>:</td><td>"
            "        <a href='http://www.dostips.com/'><b>http://www.dostips.com</a><br />"
            "        <a href='http://www.dostips.com/%~n0.php'><b>http://www.dostips.com/%~nx0.php</a>"
            "        </td></tr>"
            "    <tr><td>Created by</td><td>:</td><td><a href='http://www.dostips.com/%~nx0'>"
            "        <b>%~nx0</b></a><br /><a href='#%~n0'><b>Source Code below</b></a></td></tr>"
            "</table>"
            "</div>"
            "<br /><br />"
            "<table class='center'>"
            ) do echo.%%~A>>"%z%"

echo.Creating the index ...
set /a cnt=0
for /f "tokens=1,*" %%a in ('"help|findstr /v /b /c:" " /c:"For more""') do (
    for %%A in (
            "    <tr><td><a href='#%%a'>%%a</a></td><td>%%b</td></tr>"
            ) do echo.%%~A>>"%z%"
    set /a cnt+=1
)
for %%A in (
            "</table>"
            "<br /><br />"
            ) do echo.%%~A>>"%z%"

echo.Extracting HELP text ...
call:initProgress cnt
for /f %%a in ('"help|findstr /v /b /c:" " /c:"For more""') do (
    echo.Processing %%a
    for %%A in (
            "<div class='top'><a href='#'>TOP</a></div>"
            "<h2><a name='%%a'>%%a</a></h2>"
            "<div class='helptext'><pre><xmp>"
            ) do echo.%%~A>>"%z%"
    call help %%a >>"%z%" 2>&1
    echo ^</xmp^> >>"%z%"
    for %%A in (
            "</pre></div>"
            ) do echo.%%~A>>"%z%"
    call:tickProgress
)

echo.Injecting source script ...
for %%A in (
            ""
            "<br /><br />"
            "<div class='center'>"
            "<div class='top'><a href='#'>TOP</a></div>"
            "<a name='%~n0'><h2>DOS Batch Script Source that created this Document</h2></a>"
            "This %title% has been created automatically by the following DOS batch script:"
            "<br /><br />"
            "</div>"
            "<div class='sourcebatch'><pre><xmp>"
            ) do echo.%%~A>>"%z%"
type "%~f0" >>"%z%"

echo.Creating the footer ...
echo ^</xmp^> >>"%z%"
for %%A in (
            "</pre></div>"
            ""
            "</font>"
            "</body>"
            "</html>"
            ) do echo.%%~A>>"%z%"


chcp %restore_codepage%>NUL
explorer "%z%"

:SKIP
REM.-- End of application
FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
TITLE Press any key to close the application&ECHO.&GOTO:EOF


::-----------------------------------------------------------
::helper functions follow below here
::-----------------------------------------------------------


:initProgress -- initialize an internal progress counter and display the progress in percent
::            -- %~1: in  - progress counter maximum, equal to 100 percent
::            -- %~2: in  - title string formatter, default is '[P] completed.'
set /a "ProgressCnt=-1"
set /a "ProgressMax=%~1"

set "ProgressFormat=%~2"
if "%ProgressFormat%"=="" set "ProgressFormat=[PPPP]"
set "ProgressFormat=%ProgressFormat:[PPPP]=[P] completed.%"
call :tickProgress
GOTO:EOF


:tickProgress -- display the next progress tick
set /a "ProgressCnt+=1"
SETLOCAL
set /a "per=100*ProgressCnt/ProgressMax"
set "per=%per%%%"
call title %%ProgressFormat:[P]=%per%%%
GOTO:EOF

1
非常好的方法。它停了下来 Processing SC 对我而言。但似乎它只是在等待一些输入。如此迫切 Enter 让它完成:)
Der Hochstapler

1
它很酷(处理和生成html文件),尽管它 要求你预先拥有该脚本,而它只显示命令 help 命令显示(更容易执行)。不过,多亏了输入,它非常有用。 @OliverSalzburg它也在那里停留。
amiregelz

3

这不是您正在寻找离线解决方案(您需要互联网连接来打开网页),但它是cmd命令的一个非常有用的工具和参考:

Windows CMD命令行的A-Z索引。


它很有用,但它不是我想要的。不管怎么说,还是要谢谢你。
amiregelz

@amiregelz如果您下载它是一个离线解决方案,例如用wget。
barlop

3

我知道这不是你要求的,但你可能想开始学习Powershell而不是命令提示符。微软正试图淘汰Powershell的命令提示符,因此这将是一项很好的学习技巧。

如果你在Powershell这个命令 Get-Command 将列出当前可以从所有已加载模块运行的所有命令。它将产生一个如下所示的输出:

CommandType     Name                            Definition
-----------     ----                            ----------
Cmdlet          Add-Content                     Add-Content [-Path] <String[...
Cmdlet          Add-History                     Add-History [[-InputObject] ...
Cmdlet          Add-Member                      Add-Member [-MemberType] <PS...
Cmdlet          Add-PSSnapin                    Add-PSSnapin [-Name] <String...
Cmdlet          Clear-Content                   Clear-Content [-Path] <Strin...
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.