Windows CMD Commands Practice Questions (Command Prompt)
Practice questions on Windows Command Prompt (CMD) commands such as cd, dir, and more, with explanations for every answer.
Questions
In CMD, what does typing cd by itself (with nothing after it) do?
- Shows the current folder's full path, like pwd
- Goes to your user folder
- Goes to the root of C:
- Clears the screen
You are in C:\Users\student\Documents. What does cd .. do?
- Moves to C:\Users\student
- Moves to C:\
- Moves to C:\Users
- Lists Documents
You are in C:\Users\student\Documents. What does cd \ do?
- Moves to C:\
- Moves to C:\Users\student
- Moves up one folder
- Shows an error
You are on the C: drive. How do you switch to the D: drive?
- Type D:
- Type cd D and press Enter
- Type drive D
- Type cd ..\D:
Which command changes the drive and the folder at the same time?
- cd /d D:\Games
- cd D:\Games
- chdir --drive D:\Games
- D:\Games /cd
Which character separates folders in a Windows path?
- Backslash (\)
- Forward slash (/)
- Colon (:)
- Vertical bar (|)
Which is an absolute path?
- C:\Users\student\notes.txt
- notes.txt
- ..\notes.txt
- .\notes.txt
Which command lists the files and folders in the current directory?
- dir
- ls -l
- list
- show
Which option makes dir show hidden and system files too?
- dir /a
- dir /h
- dir -a
- dir /s
What does dir /s *.txt do?
- Lists .txt files here and in subfolders
- Lists .txt files in this folder only, skipping subfolders
- Sorts the .txt files in this folder by their size
- Deletes every .txt file in this folder and below
What does dir /b show?
- Only the names
- Only the biggest files
- Only backup files
- Files sorted by date
Which command draws the folder structure as a tree?
- tree
- dir /t
- folders
- map
CMD commands and file names are not case-sensitive, so DIR and dir do the same thing.
In CMD, cd ~ takes you to your home folder, just as it does in Linux.
Which command lists the contents of the current directory in CMD?
What do you type to move up one folder? (include the space)
cd .. and cd \ always take you to the same place.
Which command creates a new folder named projects?
- mkdir projects
- new projects
- touch projects
- dir /new projects
What does mkdir school\cs\notes do if none of those folders exist?
- Creates all three folders in one step
- Shows an error because school doesn't exist
- Creates only the notes folder
- Creates a file named notes
A folder named old still has files in it. Which command deletes it and everything inside without asking?
- rd /s /q old
- rd old
- del old
- rmdir old /empty
What happens when you run rd old on a folder that still contains files?
- An error: not empty
- The folder and its files are deleted
- Only the files are deleted
- The folder is moved to the Recycle Bin
Which command deletes a file named draft.txt?
- del draft.txt
- rd draft.txt
- rm -f draft.txt
- erase /folder draft.txt
What does del *.tmp do?
- Deletes all .tmp files here
- Deletes the folder named tmp
- Deletes one file chosen at random
- Shows the .tmp files without deleting them
Which command renames report.txt to final.txt?
- ren report.txt final.txt
- rename final.txt report.txt
- copy /r report.txt final.txt
- name report.txt final.txt
Which command copies notes.txt into the backup folder?
- copy notes.txt backup
- move notes.txt backup
- xcopy /move notes.txt backup
- cp notes.txt backup
What does move notes.txt archive do (archive is a folder)?
- Moves notes.txt into the archive folder
- Copies notes.txt and keeps both
- Deletes notes.txt
- Renames the archive folder
Which command copies a folder along with all of its subfolders, including empty ones?
- xcopy src dest /s /e
- copy src dest
- move src dest
- type src dest
What does robocopy C:\data D:\backup /mir do?
- Makes D:\backup an exact mirror of C:\data
- Copies only the newest file
- Deletes C:\data after copying
- Shows the differences without copying
You run copy a.txt b.txt and b.txt already exists. What usually happens?
- CMD asks whether to overwrite b.txt
- b.txt is silently renamed to b(2).txt
- The command fails with no message
- a.txt is deleted
What does attrib +h secret.txt do?
- Hides secret.txt
- Deletes secret.txt
- Encrypts secret.txt with a password
- Makes secret.txt run as a program
Files deleted with del go to the Recycle Bin.
In CMD, wildcards like *.txt match every file whose name ends in .txt.
Which command deletes files (three letters)?
Which command renames a file? (short form)
Which commands remove a folder?
- rd
- rmdir
- del
- dir
- md
ren can move a file to a different folder or drive.
Which command prints the contents of notes.txt on the screen?
- type notes.txt
- cat notes.txt
- show notes.txt
- dir notes.txt /c
A text file is too long to read on one screen. Which command shows it a page at a time?
- more log.txt
- less log.txt
- type /page log.txt
- dir /p log.txt
Which command searches report.txt for lines containing Error?
- findstr Error report.txt
- grep Error report.txt
- search Error report.txt
- dir Error report.txt
Which option makes findstr ignore uppercase and lowercase differences?
- /i
- /c
- /v
- /n
What does findstr /v Error report.txt show?
- Lines that do NOT contain Error
- Only the lines that contain Error
- The number of lines with Error
- The line numbers of each Error
Which command finds where notepad.exe is located on the PATH?
- where notepad
- find notepad
- dir notepad
- locate notepad
What does find /c "Error" log.txt do?
- Counts lines with Error
- Deletes the lines containing Error
- Shows lines without Error
- Creates a file named Error
The find command is case-sensitive unless you add /i.
Which CMD command shows a file's contents, like cat in Linux?
Which CMD command searches files for text, similar to grep? (the more powerful one)
What does echo Hello > hi.txt do?
- Overwrites hi.txt with Hello
- Adds Hello to the end of hi.txt
- Prints Hello and also hi.txt
- Renames hi.txt to Hello
What does echo Bye >> hi.txt do?
- Appends Bye to hi.txt
- Replaces everything in hi.txt with Bye
- Deletes hi.txt
- Shows Bye twice
hi.txt contains Hello. You run echo Bye > hi.txt. What does type hi.txt show?
- Bye
- Hello Bye
- Hello
- Nothing
hi.txt contains Hello. You run echo Bye >> hi.txt. What does type hi.txt show?
- Hello Bye
- Bye
- Hello
- Bye Hello