windows-commands

Some useful windows commands

Run multiple commands in one line

How do I run two commands in one line in Windows CMD?

<cmd1> & <cmd2>

If you want the second command to execute only if the first exited successfully:

<cmd1> && <cmd2>

Set environment varialbe

setx <env_var_name> <env_var_value>

Comment

批次檔中特殊符號@、::、%的用途

REM this is comment
:: this is another comment

where(linux whereis/which)

Windows equivalent of whereis?

where powershell
# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Show file structure

tree /f

use /f to show files

Remove directory

“rm -rf” equivalent for Windows?

rd -r -force "path" # -r for recursive

Search for large files

4 Ways To Find Large Files In Windows 10

Find all files larger than 1GB and write their paths to the file "/path/to/largefiles.txt".

forfiles /S /M * /C “cmd /c if @fsize GEQ 1073741824 echo @path > "/path/to/largefiles.txt"

Merge text files

How to Merge Text (.Txt) Files in Command Prompt

copy *.txt "merged.txt"

Copy multiple files

Can Windows' copy command handle multiple files?

for %%I in ("C:\dirA\*.dll" "C:\dirB\*.dll") do copy /Y %%I "C:\targetDir\"

Copy recursively:

xcopy directories and subdirectories recursively and filter only filenames by extension

xcopy "C:\source\dirA*" "dirA\" /sy

Create a symbolic link

mklink /d <link_name> <target>

find computer name holding shared folder

net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK                     \\abc\def            Microsoft Windows Network
The command completed successfully.

display DNS table

ipconfig /displaydns

server cannot be accessed by name but with ip

Server network cannot access with name but accessible with ip

ipconfig /flushdns

find the ip address of computer holding shared folder

Find the IP address of a Mapped Network drive in Windows

After finding the computer name as "abc" using net use:

ping abc -4

cd to UNC path

Browse an UNC path using Windows CMD without mapping it to a network drive

pushd "\\network_host\a\network\path"
:: go back
popd

log out from Windows network sharing

Disconnecting / logging out from Windows network share without restarting Workstation service

net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK                     \\abc\def            Microsoft Windows Network
The command completed successfully.
net use \\abc\def /DELETE
\\abc\def was deleted successfully.
net use
New connections will be remembered.

There are no entries in the list.

Then go to 控制台\使用者帳戶\認證管理員, clear your credential.

Disconnect to internet, try to access your network sharing on disconnection, and then connect to internet.

unhide folder

I can't unhide my folders using folder options

attrib -h -s  /s /d "/path/to/folder"

7zip: exclude file lists and specific type of files

7-zip - how to use command line to include/exclude large list of files

Add to a 7-Zip archive: How to exclude certain file types/extensions?

7z.exe a Archive.7z . -r -x!*.avi -x!*.mp4 -x!*.pcd -x!*.ply  -xr@"merged.txt"

check pid by port(Linux netstat)

Windows 如何找到佔用 port 的程式?

netstat -ano | findstr <port_number>

get program name by pid(Linux ps)

Windows 如何找到佔用 port 的程式?

tasklist | findstr <pid>