09-03-2024, 01:44 AM
Comprehensive List of Batch Commands with Descriptions
Batch scripting in Windows uses a variety of commands to perform tasks such as file manipulation, system administration, and task automation. Below is a comprehensive list of Batch commands with descriptions.
1. @echo off
Description: Turns off the display of commands in the script. Only the output of the commands will be shown.
2. echo
Description: Displays a message or turns the command echoing on or off.
3. pause
Description: Pauses the script and displays a message prompting the user to press any key to continue.
4. cls
Description: Clears the Command Prompt window.
5. REM
Description: Adds a comment in the script. Comments are ignored during execution.
6. set
Description: Sets or displays environment variables. Can also be used to prompt for user input.
7. if
Description: Performs conditional processing in a Batch script.
8. for
Description: Iterates over a set of files, a range of numbers, or the contents of a directory.
9. goto
Description: Directs the script to jump to a labeled section within the script.
10. call
Description: Calls another Batch script or function within the script. Returns to the calling script when the called script completes.
11. exit
Description: Exits the Command Prompt or terminates the script. Can also return an exit code.
12. start
Description: Starts a separate window to run a specified program or command.
13. dir
Description: Displays a list of files and directories in the current directory.
14. cd
Description: Changes the current directory.
15. mkdir (md)
Description: Creates a new directory.
16. rmdir (rd)
Description: Removes a directory. The `/s` option removes the directory and all its contents.
17. del (erase)
Description: Deletes one or more files. The `/q` option suppresses confirmation prompts.
18. copy
Description: Copies one or more files to another location.
19. xcopy
Description: Copies files and directories, including subdirectories. Useful for backups.
20. move
Description: Moves one or more files or directories from one location to another.
21. ren (rename)
Description: Renames a file or directory.
22. attrib
Description: Changes the attributes of a file or directory. Attributes include read-only, hidden, system, and archive.
23. tasklist
Description: Displays a list of currently running processes.
24. taskkill
Description: Ends one or more tasks or processes. Use `/f` to forcefully terminate a process.
25. shutdown
Description: Shuts down, restarts, or logs off the computer.
26. netstat
Description: Displays network statistics, active connections, and listening ports.
27. ipconfig
Description: Displays IP network configuration information.
28. ping
Description: Sends ICMP echo requests to network hosts to check connectivity.
29. findstr
Description: Searches for a specific text string in files or input.
30. title
Description: Sets the title of the Command Prompt window.
31. color
Description: Changes the foreground and background colors of the Command Prompt.
32. cls
Description: Clears the Command Prompt window.
33. time
Description: Displays or sets the system time.
34. date
Description: Displays or sets the system date.
35. ver
Description: Displays the version of the Windows operating system.
36. help
Description: Provides help information for commands. Use `help` followed by a command name for detailed information.
Conclusion
This list of Batch commands provides a solid foundation for creating and understanding Batch scripts. By mastering these commands, you can automate tasks, manage files, and configure your Windows environment with ease. Experiment with these commands, combine them in scripts, and start automating your workflows.
Happy Scripting!
Batch scripting in Windows uses a variety of commands to perform tasks such as file manipulation, system administration, and task automation. Below is a comprehensive list of Batch commands with descriptions.
1. @echo off
Description: Turns off the display of commands in the script. Only the output of the commands will be shown.
Code:
@echo off
2. echo
Description: Displays a message or turns the command echoing on or off.
Code:
echo Hello, World!
echo off
echo on
3. pause
Description: Pauses the script and displays a message prompting the user to press any key to continue.
Code:
pause
4. cls
Description: Clears the Command Prompt window.
Code:
cls
5. REM
Description: Adds a comment in the script. Comments are ignored during execution.
Code:
REM This is a comment
6. set
Description: Sets or displays environment variables. Can also be used to prompt for user input.
Code:
set myVar=Hello
set /p name=Enter your name:
7. if
Description: Performs conditional processing in a Batch script.
Code:
if %age% GEQ 18 echo You are an adult.
if exist file.txt echo File exists.
if not exist file.txt echo File does not exist.
8. for
Description: Iterates over a set of files, a range of numbers, or the contents of a directory.
Code:
for %%i in (*.txt) do echo %%i
for /l %%i in (1,1,10) do echo %%i
9. goto
Description: Directs the script to jump to a labeled section within the script.
Code:
goto start
:start
echo This is the start.
10. call
Description: Calls another Batch script or function within the script. Returns to the calling script when the called script completes.
Code:
call otherScript.bat
call :functionName
11. exit
Description: Exits the Command Prompt or terminates the script. Can also return an exit code.
Code:
exit
exit /b 0
12. start
Description: Starts a separate window to run a specified program or command.
Code:
start notepad.exe
start cmd /k dir
13. dir
Description: Displays a list of files and directories in the current directory.
Code:
dir
dir /p
dir /s
14. cd
Description: Changes the current directory.
Code:
cd \path\to\directory
cd ..
cd /
15. mkdir (md)
Description: Creates a new directory.
Code:
mkdir myfolder
md myfolder
16. rmdir (rd)
Description: Removes a directory. The `/s` option removes the directory and all its contents.
Code:
rmdir myfolder
rd /s myfolder
17. del (erase)
Description: Deletes one or more files. The `/q` option suppresses confirmation prompts.
Code:
del file.txt
del /q *.txt
erase file.txt
18. copy
Description: Copies one or more files to another location.
Code:
copy source.txt destination.txt
copy *.txt C:\backup\
19. xcopy
Description: Copies files and directories, including subdirectories. Useful for backups.
Code:
xcopy C:\source\* C:\destination\ /s /e
20. move
Description: Moves one or more files or directories from one location to another.
Code:
move file.txt C:\newfolder\
move C:\source\* C:\destination\
21. ren (rename)
Description: Renames a file or directory.
Code:
ren oldname.txt newname.txt
rename oldname.txt newname.txt
22. attrib
Description: Changes the attributes of a file or directory. Attributes include read-only, hidden, system, and archive.
Code:
attrib +r file.txt
attrib -h +s file.txt
attrib +a /s /d
23. tasklist
Description: Displays a list of currently running processes.
Code:
tasklist
tasklist /fi "imagename eq notepad.exe"
24. taskkill
Description: Ends one or more tasks or processes. Use `/f` to forcefully terminate a process.
Code:
taskkill /im notepad.exe
taskkill /pid 1234 /f
25. shutdown
Description: Shuts down, restarts, or logs off the computer.
Code:
shutdown /s /f /t 0
shutdown /r /t 60
shutdown /l
26. netstat
Description: Displays network statistics, active connections, and listening ports.
Code:
netstat
netstat -an
27. ipconfig
Description: Displays IP network configuration information.
Code:
ipconfig
ipconfig /all
ipconfig /release
ipconfig /renew
28. ping
Description: Sends ICMP echo requests to network hosts to check connectivity.
Code:
ping 192.168.1.1
ping www.google.com
ping -t 8.8.8.8
29. findstr
Description: Searches for a specific text string in files or input.
Code:
findstr "Hello" file.txt
findstr /s /i "error" *.log
30. title
Description: Sets the title of the Command Prompt window.
Code:
title My Batch Script
31. color
Description: Changes the foreground and background colors of the Command Prompt.
Code:
color 0A
color 1F
32. cls
Description: Clears the Command Prompt window.
Code:
cls
33. time
Description: Displays or sets the system time.
Code:
time
time /t
34. date
Description: Displays or sets the system date.
Code:
date
date /t
35. ver
Description: Displays the version of the Windows operating system.
Code:
ver
36. help
Description: Provides help information for commands. Use `help` followed by a command name for detailed information.
Code:
help
help xcopy
Conclusion
This list of Batch commands provides a solid foundation for creating and understanding Batch scripts. By mastering these commands, you can automate tasks, manage files, and configure your Windows environment with ease. Experiment with these commands, combine them in scripts, and start automating your workflows.
Happy Scripting!