1. File and Directory Management:
attrib: Displays or changes file or directory attributes (hidden, read-only, archive, etc.).- Syntax:
attrib [+r|-r] [+a|-a] [+s|-s] [+h|-h] [drive:][path]filename - Options:
+r: Set read-only attribute-r: Clear read-only attribute+a: Set archive attribute-a: Clear archive attribute+s: Set system attribute-s: Clear system attribute+h: Set hidden attribute-h: Clear hidden attribute
- Examples:
attrib +h myfile.txt: Makemyfile.txthidden.attrib -r myfile.txt: Remove the read-only attribute frommyfile.txt.attrib *.*: Display attributes of all files in the current directory.
- Syntax:
cdorchdir: Changes the current directory.- Syntax:
cd [path]orchdir [path] - Options:
..: Go to the parent directory.\: Go to the root of the drive.
- Examples:
cd Documents: Go to theDocumentsfolder in the current directory.cd C:\Users\User\Downloads: Go to theDownloadsfolder on drive C.cd ..: Go to the parent directory.cd \: Go to the root of the current drive.
- Syntax:
copy: Copies one or more files.- Syntax:
copy [source_file] [destination_file] - Options:
/a– Copy an ASCII file/b– Copy a binary file/v– Verify that files were copied correctly
- Examples:
copy myfile.txt mycopy.txt: Copymyfile.txttomycopy.txt.copy *.txt C:\Backup: Copy all files with the.txtextension to theC:\Backupfolder.
- Syntax:
delorerase: Deletes one or more files.- Syntax:
del [filename]orerase [filename] - Options:
/p: Prompt for confirmation before deleting each file./f: Force deletion of read-only files./s: Delete files from subdirectories./q– Delete files without prompting.
- Examples:
del myfile.txt: Deletemyfile.txt.del *.tmp: Delete all files with the.tmpextension.del /f /s *.log– Delete all files with the .log extension in the current directory and all subdirectories, without confirmation.
- Syntax:
dir: Displays a list of files and directories in the current directory.- Syntax:
dir [path] [options] - Options:
/a: Display all files (including hidden ones)./w: Display the list in wide format./p: Display the list page by page./s: Display files from subdirectories as well./b– Display only the file name.
- Examples:
dir: Display a list of files and directories in the current directory.dir C:\Users\User\Documents /a: Display all files in theDocumentsdirectory.dir /w: Display a list of files and directories in the current directory in wide format.dir /b /s *.txt: Show all *.txt files with their full path.
- Syntax:
mkdirormd: Creates a new directory.- Syntax:
mkdir [path]ormd [path] - Examples:
mkdir NewFolder: Create a new folderNewFolderin the current directory.mkdir C:\Backup: Create a newBackupfolder on driveC.
- Syntax:
move: Moves one or more files or directories.- Syntax:
move [source_file] [destination_file] - Examples:
move myfile.txt C:\Documents: Movemyfile.txtto theC:\Documentsfolder.move dir1 dir2– Move folderdir1to folderdir2.
- Syntax:
rdorrmdir: Deletes a directory.- Syntax:
rd [path]orrmdir [path] - Options:
/s: Delete the directory with all its subdirectories./q– Delete the directory without prompting.
- Examples:
rd myfolder: Delete the empty foldermyfolder.rd /s /q myfolder– Delete themyfolderdirectory with all its contents without prompting.
- Syntax:
renorrename: Renames a file or directory.- Syntax:
ren [old_name] [new_name] - Examples:
ren myfile.txt newfile.txt: Renamemyfile.txttonewfile.txt.
- Syntax:
type: Displays the content of a text file.- Syntax:
type [filename] - Example:
type myfile.txt: Display the content ofmyfile.txt.
- Syntax:
xcopy: Copies files and directories (including subdirectories).- Syntax:
xcopy [source] [destination] [options] - Options:
/s: Copy directories and subdirectories (except empty ones)./e: Copy directories and subdirectories (including empty ones)./i: If the destination does not exist, create it./y: Suppress prompt to confirm overwriting./d– Copy only newer files.
- Examples:
xcopy C:\Source D:\Destination /s: Copy theC:\Sourcedirectory to all subdirectories in theD:\Destinationfolder.xcopy C:\Source D:\Destination /e /y: Copy theC:\Sourcedirectory to all subdirectories in theD:\Destinationfolder, including empty ones and without prompting for overwrite.
- Syntax:
2. Disk Management:
diskpart: Launches the disk management utility (partitions, volumes).- Syntax:
diskpart - Notes:
diskpartis an interactive utility that has its own set of commands.- Administrator rights are required to use it.
- You can learn more about using
diskpartwith thehelpcommand within the utility.
- Syntax:
format: Formats a disk.- Syntax:
format [drive:] [options] - Options:
/q– Quick format/fs:file-system– Choose file system type (e.g., NTFS, FAT32)
- Examples:
format D: /q: Quick format of drive D:.format E: /fs:NTFS: Format drive E: to NTFS file system.
- Warning: Formatting a disk deletes all data on it!
- Syntax:
label: Sets or changes the disk label.- Syntax:
label [drive:][label] - Examples:
label D: NewLabel– Set the label on drive D to NewLabel.label D:– Clear the label from drive D.
- Syntax:
3. System Management:
cls: Clears the command prompt screen.- Syntax:
cls
- Syntax:
date: Displays or changes the current date.- Syntax:
date [new_date] - Examples:
date: Display the current date.date 12-25-2024: Change the date to December 25, 2024.
- Syntax:
exit: Exits the command prompt.- Syntax:
exit
- Syntax:
shutdown: Shuts down or restarts the computer.- Syntax:
shutdown [options] - Options:
/s: Shut down the computer./r: Restart the computer./a: Abort shutdown or restart./t xxx– Delay in seconds before shutdown or restart.
- Examples:
shutdown /s /t 60: Shut down the computer in 60 seconds.shutdown /r: Restart the computer.shutdown /a: Abort scheduled shutdown or restart.
- Syntax:
tasklist: Displays a list of running processes.- Syntax:
tasklist [options] /v– Verbose information./fo csv– Output in CSV format./fi "imagename eq notepad.exe"– Find all notepad processes.- Examples:
tasklist: Show a list of running processes.tasklist /v: Show a list of running processes with detailed information.
- Syntax:
taskkill: Terminates a process.- Syntax:
taskkill [options] - Options:
/im imagename– Terminate process by image name./pid pid– Terminate process by ID./f– Forcefully terminate process.
- Examples:
taskkill /im notepad.exe: Terminate all processes with the namenotepad.exe.taskkill /pid 1234: Terminate the process with ID 1234.taskkill /im notepad.exe /f– Forcefully terminate allnotepad.exeprocesses.
- Syntax:
time: Displays or changes the current time.- Syntax:
time [new_time] - Examples:
time: Display the current time.time 15:30: Set the time to 15:30.
- Syntax:
ver: Displays the operating system version.- Syntax:
ver
- Syntax:
systeminfo: Displays detailed system information.- Syntax:
systeminfo
- Syntax:
taskmgr: Launches Task Manager.- Syntax:
taskmgr
- Syntax:
4. Network:
ipconfig: Displays network configuration.- Syntax:
ipconfig [options] - Options:
/all: Display full information about network adapters./release: Release the IP address./renew: Request a new IP address.
- Examples:
ipconfig: Display basic network configuration.ipconfig /all: Display full information about all network adapters.ipconfig /release– Release IP address.ipconfig /renew– Request a new IP address.
- Syntax:
ping: Sends an echo request to another computer on the network.- Syntax:
ping [hostname_or_ip_address] [options] -n xxx– Number of requests.-t– Ping indefinitely.- Examples:
ping google.com: Ping thegoogle.comserver.ping 192.168.1.100: Ping the computer with IP address192.168.1.100.ping google.com -n 10– Perform 10 pings.
- Syntax:
tracert: Displays the path of packets to another computer on the network.- Syntax:
tracert [hostname_or_ip_address] - Example:
tracert google.com: Display the path of packets togoogle.com.
- Syntax:
netstat: Displays network connections.- Syntax:
netstat [options] - Options:
-a: Shows all connections.-b: Shows applications that created connections.
- Examples:
netstat– Show all active connections.netstat -a -b– Show all connections and the running applications that opened them.
- Syntax:
nslookup: Queries DNS information.- Syntax:
nslookup [hostname] - Example:
nslookup google.com: Query DNS information forgoogle.com.
- Syntax:
5. Other Commands:
assoc: Displays or changes file associations.- Syntax:
assoc [.extension]=[file_type] - Examples:
assoc .txt: Display the file type for the.txtextension.assoc .txt=txtfile: Set the file type for the.txtextension totxtfile.
- Syntax:
call: Calls one batch file from another.- Syntax:
call [batch_file_name] - Example:
call mybatch.bat: Call the batch filemybatch.bat.
- Syntax:
chcp: Changes the console code page.- Syntax:
chcp [code_page_number] - Examples:
chcp 1251: Set the code page for Cyrillic.chcp: Display the current code page.
- Syntax:
choice: Allows the user to choose from a list of options.- Syntax:
choice [/c [options]] [/n] [/t [seconds]] [/d [option]] [text] - Options:
/c: Specifies available options./n: Hides the list of available options./t: Specifies the timeout (in seconds)./d: Specifies the default option.
- Example:
choice /c yn /t 10 /d n "Do you really want to exit?"
- Syntax:
find: Searches for a text string in a file.- Syntax:
find "string" [filename] - Examples:
find "Hello" myfile.txt– Searches for the string “Hello” in myfile.txt.
- Syntax:
findstr: Searches for text strings in files (more powerful thanfind).- Syntax:
findstr [options] "string" [filename] - Options:
/i– Case-insensitive search./n– Display line numbers./s– Search in all subdirectories.
- Examples:
findstr /i "error" myfile.log: Searches for the string “error” (case-insensitive) inmyfile.log.findstr /n "error" *.log– Searches for the string “error” in all .log files and shows line numbers.
- Syntax:
gpupdate: Updates group policies.- Syntax:
gpupdate [options] - Options:
/force– Force update.
- Example:
gpupdate /force– Force update group policies.
- Syntax:
helpor/?: Displays help for a command.- Syntax:
help [command_name]or[command_name] /? - Example:
help dirordir /?: Display help for thedircommand.
- Syntax:
pause: Pauses batch file execution and waits for a key press.- Syntax:
pause
- Syntax:
path: Displays or changes the PATH environment variables.- Syntax:
path [path] - Examples:
path: Show the current value of the PATH variable.path C:\bin– Add the C:\bin folder to the PATH variable.
- Syntax:
prompt: Customizes the command prompt string.- Syntax:
prompt [text] - Examples:
prompt $p$g: Set the prompt string to the current path.prompt MyPrompt>: Set the prompt string toMyPrompt>.
- Syntax:
set: Displays, sets, or removes environment variables.- Syntax:
set [name=[value]] - Examples:
set: Display all environment variables.set myvar=myvalue: Set the environment variablemyvartomyvalue.set myvar=: Remove the environment variablemyvar.
- Syntax:
start: Launches a program or opens a file.- Syntax:
start [program_or_file_name] [options] - Examples:
start notepad.exe: Launch Notepad.start myfile.txt: Openmyfile.txtwith the default program.start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" "https://www.google.com"– Open a website in Chrome.
- Syntax:
tree: Displays the graphical directory structure.- Syntax:
tree [drive:][path] [options] - Options:
/f: Also display file names./a– Use ASCII characters.
- Examples:
tree– Show the structure of the current directory.tree /f– Show the structure of the current directory with files.
- Syntax:
where: Locates a file.- Syntax:
where [filename] - Example:
where notepad.exe
- Syntax:
6. Batch File Commands:
echo: Displays text on the screen.- Syntax:
echo [text] echo on– Enable command display when executing a batch file.echo off– Disable command display when executing a batch file.- Examples:
echo Hello, world!: Display “Hello, world!”.echo off– Disable command output.echo on– Enable command output.
- Syntax:
rem: Adds a comment to a batch file.- Syntax:
rem [comment] - Example:
rem This is a comment
- Syntax:
goto: Jumps to a label.- Syntax:
goto [label] - Example:
batch :start echo Hello goto end echo This will not be displayed :end echo Goodbye
- Syntax:
if: Performs conditional logic.- Syntax:
if [not] condition (command1) else (command2) - Examples:
if exist file.txt echo file exists– Check for file existence.if %var%== "text" echo variable has value– Check variable value.
- Syntax:
for: Performs a loop action.- Syntax:
for %%variable in (set) do [command] - Example:
batch for %%a in (*.txt) do ( echo %%a type %%a echo ------------- )- Display the name of each
.txtfile and its content.
- Display the name of each
- Syntax:
Warning:
- Be careful when using commands that can modify the system, especially when used with administrator privileges.
- Before executing the
formatcommand, make sure you have selected the correct drive.