Windows CMD

最後更新: 2019-05-17

目錄

  • cmd with multi-line cmd (^)
  • findstr
  • find
  • 現在時間
  • Process Management(tasklist)
  • Permission
  • open command prompt in current folder

 


cmd with multi-line cmd (^)

 

In the Windows Command Prompt the ^ is used to escape the next character on the command line.

copy file1.txt ^
 file2.txt

 


findstr

 

Opts

  • /r    # regular expression
  • /s    # 在目前目錄并包含子目錄搜尋
  • /i    # 忽略大小寫差異
  • /v   #把不包含的那行內容輸出
  • /n  # 把符合條件的行數列出
  • /m  # 如果有找到符合的內容,僅列出檔案名稱

ie.

findstr /r "[^0-9]" t1.txt

netstat -a -p tcp -n | findstr 8443

 


find

 

i.e. Get the line count of a text file

# string 必須要 ""

#  /c         Displays only the count of lines containing the string.

find /c "string" myfile.txt

i.e. 數行數

# /V         Displays all lines NOT containing the specified string.

find /c /v ""

i.e 忽略大小寫

netstat -nao | find /i “estab”

 


現在時間

 

@echo %time%

10:31:53.67

 


Process Management

 

tasklist

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0          8 K
System                           4 Services                   0      5,344 K
Registry                        88 Services                   0     26,244 K
smss.exe                       340 Services                   0        944 K
...

tskill / taskkill

tskill notepad

 * tasklist, taskkill 依賴 WMI Service

C:\>tasklist

ERROR: The specified module could not be found.

Fix

sc config winmgmt start= demand
net start winmgmt

tasklist

  1. # /F                         # 強制終止處理程序
  2. # /IM   imagename   # 指定要終止影像名稱, 可使用萬用字元 '*'

Permission

 

cacls filename /D user

 


open command prompt in current folder

 

[Win10]

Just go to your folder location and type "cmd" on the address bar.

Alt+D, type cmd

    OR

Ctrl + L, type cmd

[Win7]

In win7/8, try right click while holding shift key, should have cmd prompt here

win10 變了 powershell

 


Other

 

batch script