How to use the Window command line (DOS)
Issue
How to use the Windows command line (DOS).
Solution
This document covers the basic in navigating and using the Microsoft Windows command line. On this page, you'll learn how to move around in the command line, find files, manipulate files, and other important commands. Keep in mind that there are well over 100 different commands that have been used in MS-DOS and the Windows command line. If you're interested in learning every command, see our Microsoft DOS and command prompt help page, which gives a description and example about each of these commands.
Get into the Windows command line
Open a Windows command line window by following the below steps. If you need additional information or alternative methods for all versions of Windows, see our how to get into DOS and Windows command line page.
- Click Start
- In the Search or Run line type cmd and press enter.
Understanding the prompt
After following the above steps, the below black box will open, this is the Windows command line. By default Windows will take you to your users directory. In the below example, the user is Mrhope, so we're in the C:\Users\Mrhope directory and our prompt is C:\Users\Windows>. From this prompt information we know we're in the C: drive (the default drive letter of the hard drive) and currently in the Mrhope directory, which is a subdirectory of the Users directory.
Key tips
- MS-DOS and the Windows command line are not case sensitive.
- The files and directories shown in Windows are also found in the command line.
- When working with a file or directory with a space, surround it in quotes. For example, My Documents would be "My Documents".
- Filenames can have a long file name of 255 characters and a 3 character file extension.
- When a file or directory is deleted in the command line, it is not moved into the Recycle bin.
- If you need help with any of command type /? after the command. For example, dir /? would give the options available for the dir command.
Listing the files
Lets learn your first command. Type dir at the prompt to list files in the current directory. You should get an output similar to the below image example. By default, without using any dir options this is how dir output will appear. As can be seen, you're given a lot of useful information, the modification or creation date and time, an indication if the listed item is a directory (<DIR>), and the actual name of the directory or file. In the below example, there are 0 files listed and 14 directories as indicated by the status at the bottom of the output.
Every command in the command line has options, which are additional switches and commands that can be added after the command. For example, with the dir command you can type dir /p to list the files and directories in the current directory one page at a time. This switch is useful to see all the files and directories in a directory that has dozens or hundreds of files. Each of the options and switches for each command is listed on our DOS command page. For example, if you want to see all the options for dir see our dir command page for a full listing.
In addition to switches, the dir command can also be used to search for specific files and directories by using wildcards. For example, if you only wanted to list files or directories that begin with the letter A you could type dir a* to list only the AppData directory, in this above example. See the wildcard definition for several other examples and help with using wildcards.
Moving into a directory
Now that we've seen a list of directories (shown above) available in the current directory lets move into one of those directories. To move into a directory, we use the cd command, so to move into the Desktop type cd desktop and press enter. Once you've moved into a new directory the prompt should change, so in our example, the prompt is now C:\Users\Mrhope\Desktop>. Now in this directory lets see what files are found in this directory by typing the dir command again.
Understand the files
Now in the Desktop directory in this example (as shown above), we now have 23 files and 7 directories. As can be seen in the above example, there are several different file types. In Windows, you're familiar with files having icons that help represent the type of files. In the command line, the same thing is accomplished by the file extensions. For example, "forum posts.txt" is a text file because it has a .txt file extension, Time.mp3 is a MP3 music file, and minecraft.exe is an executable file.
For most users, you'll only be concerned with executable files, which as mentioned above is a file that ends with .exe and are also files that end with .com and .bat. When the name of these files is typed the program will run. This would be the same thing as double-clicking a file in Windows to open the program. For example, if we wanted to run minecraft.exe typing minecraft at the prompt will run that program. Keep in mind though that if the executable file you're trying to run is not in the current directory you'll get an error.
If you wish to view the contents of a file, most versions of the command line use the edit command. For example, if we wanted to look at the log file hijackthis.log we would type edit hijackthis.log at the prompt. For 64-bit versions of Windows that do not support this command you can use the start command, for example, type start notepad hijackthis.log to open the file in Notepad.
Moving back a directory
You learned earlier the cd command can move into a directory. This command also allows you to go back a directory by typing cd.. at the prompt. When this command is typed you'll be moved out of the Desktop directory and back into the user directory. If you wanted to move back to the root directory typing cd\ takes you to the C:\> prompt. If you know the name of the directory you wish to move into, you can also type cd\ and the directory name. For example, to move into C:\Windows> you would type cd\windows at the prompt.
Creating a directory
Now with your basic understanding of navigating the command line lets start creating. To create a directory in the current directory use the mkdir command. For example, lets create a directory called test by typing mkdir test at the prompt. If created successfully you should be returned to the prompt with no error message. After the directory has been created, move into that directory with the cd command.
Creating a new batch file
Now in the newly created test directory lets create your fist file. In most situations, you will never need to create any file at the command line, however, it's still good to understand how files are created. In this example, we will be creating a batch file. A batch file is a file that ends with .bat and is a file that can help automate frequently used commands in the command line. We will be calling this batch file example, so type edit example.bat at the prompt. As mentioned earlier if the edit command doesn't work use the start command to open the batch file in notepad, so you type start notepad example.bat at the prompt.
Either of these commands will open a new blank window for the example.bat file. In the blank file, type the below three lines, which will clear the screen with the cls command and then run the dir command.
@echo off
cls
dir
cls
dir
After these three lines have been typed into the file save and exit the file. If you're in the edit command Click File (or press Alt+F) and then Save. After the file has been saved and you're back into the command prompt, typing dir should display the example.bat in the test directory.
Now run the batch file to get a better understanding of what a batch file does. To run the batch file type example at the prompt. This will execute the batch file causing it to clear the screen and then do the dir command and display the directory listing of the test directory.
Moving and copying a file
Now that we've created a file lets move it into an alternate directory. To help make things easier lets create another directory to move the file into. So, type mkdir dir2 to create a new directory in the test directory called dir2. After the new directory has been created, use the move command to move the example.bat file into that directory type move example.bat dir2 which should return a message indicating that one file was moved. You could also substitute the move command for the copy command to copy the file instead of moving it.
Rename a file
After the file has been moved into the dir2 directory lets move into that directory with the cd command so we can rename the file. In the dir2 directory lets use the rename command to rename the example file into an alternate name. Type rename example.bat first.bat at the prompt to rename the file to first.bat. Now when using the dir command you should see the first.bat as the only file.
When renaming any file make sure the file has the same file extension. If you were to rename a .bat file to a .txt file, it is no longer an executable file only a text file. Also, keep in mind that renaming the file to a different file extension does not convert the file. For example, if you were to name the file to a .MP3 file it may look like a MP3 audio file in Windows, but it is not going to play music.
Deleting a file
Now that we've had our fun with our new file lets delete the file with the del command. Type del first.bat to delete the first.bat file. If successful, you will be returned to the prompt with no errors and the dir command will show no files in the current directory.
When deleting files you can also use wildcards to delete multiple files at once. For example, if the directory contained several .GIF image files you could type del *.gif to delete all files ending with the .gif file extension.
Renaming a directory
Lets go back one directory to get back into the test directory by using the cd.. command mentioned earlier. Lets now rename our del2 directory to something else using the same rename command we used earlier. At the prompt, type rename dir2 hope to rename the directory to hope. After this command has been completed, type dir and you should now see one directory called hope.
Removing a directory
Still in the test directory lets now remove the hope directory by using the rmdir command. At the prompt, type rmdir hope to remove the hope directory.
If the directory you're trying to remove contains any files or directories, you'll receive an error. To prevent this error use the /s option. For example, if the hope directory still had the first.bat file you would need to type rmdir /s hope at the prompt.
In conclusion
Following all of the above sections you should now have a good understanding on how to navigate in the command line, create directories and files, rename files and directories, and delete files and directories. As mentioned earlier, there are hundreds of other commands that can be used at the command line. If you want to expand your knowledge even more, we highly recommend looking at the options available for each of the above commands and go through our commands overview.
MS-DOS and command line overview
Below is a listing of each of the MS-DOS commands currently listed on Computer Hope and a brief explanation of what each of the commands do. The below commands are all MS-DOS commands, which means not all the below commands will work in your version of MS-DOS or Windows command line. Clicking on the command will open the help page for that command with full details about it.
Command | Description | Type |
ansi.sys | Defines functions that change display graphics, control cursor movement, and reassign keys. | File |
append | Causes MS-DOS to look in other directories when editing a file or running a command. | External |
arp | Displays, adds, and removes arp information from network devices. | External |
assign | Assign a drive letter to an alternate letter. | External |
assoc | View the file associations. | Internal |
at | Schedule a time to execute commands or programs. | External |
atmadm | Lists connections and addresses seen by Windows ATM call manager. | Internal |
attrib | Display and change file attributes. | External |
batch | Recovery console command that executes a series of commands in a file. | Recovery |
bootcfg | Recovery console command that allows a user to view, modify, and rebuild the boot.ini | Recovery |
break | Enable / disable CTRL + C feature. | Internal |
cacls | View and modify file ACL's. | External |
call | Calls a batch file from another batch file. | Internal |
cd | Changes directories. | Internal |
chcp | Supplement the International keyboard and character set information. | External |
chdir | Changes directories. | Internal |
chdsk | Check the hard disk drive running FAT for errors. | External |
chkntfs | Check the hard disk drive running NTFS for errors. | External |
choice | Specify a listing of multiple options within a batch file. | External |
cls | Clears the screen. | Internal |
cmd | Opens the command interpreter. | |
color | Easily change the foreground and background color of the MS-DOS window. | Internal |
command | Opens the command interpreter. | |
comp | Compares files. | External |
compact | Compresses and uncompress files. | External |
control | Open Control Panel icons from the MS-DOS prompt. | External |
convert | Convert FAT to NTFS. | External |
copy | Copy one or more files to an alternate location. | Internal |
ctty | Change the computers input/output devices. | Internal |
date | View or change the systems date. | Internal |
debug | Debug utility to create assembly programs to modify hardware settings. | External |
defrag | Re-arrange the hard disk drive to help with loading programs. | External |
del | Deletes one or more files. | Internal |
delete | Recovery console command that deletes a file. | Internal |
deltree | Deletes one or more files or directories. | External |
dir | List the contents of one or more directory. | Internal |
disable | Recovery console command that disables Windows system services or drivers. | Recovery |
diskcomp | Compare a disk with another disk. | External |
diskcopy | Copy the contents of one disk and place them on another disk. | External |
doskey | Command to view and execute commands that have been run in the past. | External |
dosshell | A GUI to help with early MS-DOS users. | External |
drivparm | Enables overwrite of original device drivers. | Internal |
echo | Displays messages and enables and disables echo. | Internal |
edit | View and edit files. | External |
edlin | View and edit files. | External |
emm386 | Load extended Memory Manager. | External |
ename | Recovery console command to enable a disable service or driver. | Recovery |
endlocal | Stops the localization of the environment changes enabled by the setlocal command. | Internal |
erase | Erase files from computer. | Internal |
exit | Exit from the command interpreter. | Internal |
expand | Expand a Microsoft Windows file back to it's original format. | External |
extract | Extract files from the Microsoft Windows cabinets. | External |
fasthelp | Displays a listing of MS-DOS commands and information about them. | External |
fc | Compare files. | External |
fdisk | Utility used to create partitions on the hard disk drive. | External |
find | Search for text within a file. | External |
findstr | Searches for a string of text within a file. | External |
fixboot | Writes a new boot sector. | Recovery |
fixmbr | Writes a new boot record to a disk drive. | Recovery |
for | Boolean used in batch files. | Internal |
format | Command to erase and prepare a disk drive. | External |
ftp | Command to connect and operate on a FTP server. | External |
ftype | Displays or modifies file types used in file extension associations. | Recovery |
goto | Moves a batch file to a specific label or location. | Internal |
graftabl | Show extended characters in graphics mode. | External |
help | Display a listing of commands and brief explanation. | External |
if | Allows for batch files to perform conditional processing. | Internal |
ifshlp.sys | 32-bit file manager. | External |
ipconfig | Network command to view network adapter settings and assigned values. | External |
keyb | Change layout of keyboard. | External |
label | Change the label of a disk drive. | External |
lh | Load a device driver in to high memory. | Internal |
listsvc | Recovery console command that displays the services and drivers. | Recovery |
loadfix | Load a program above the first 64k. | External |
loadhigh | Load a device driver in to high memory. | Internal |
lock | Lock the hard disk drive. | Internal |
logoff | Logoff the currently profile using the computer. | External |
logon | Recovery console command to list installations and enable administrator login. | Recovery |
map | Displays the device name of a drive. | Recovery |
md | Command to create a new directory. | Internal |
mem | Display memory on system. | External |
mkdir | Command to create a new directory. | Internal |
mode | Modify the port or display settings. | External |
more | Display one page at a time. | External |
move | Move one or more files from one directory to another directory. | Internal |
msav | Early Microsoft Virus scanner. | External |
msd | Diagnostics utility. | External |
msdex | Utility used to load and provide access to the CD-ROM. | External |
nbtstat | Displays protocol statistics and current TCP/IP connections using NBT | External |
net | Update, fix, or view the network or network settings | External |
netsh | Configure dynamic and static network information from MS-DOS. | External |
netstat | Display the TCP/IP network protocol statistics and information. | External |
nlsfunc | Load country specific information. | External |
nslookup | Look up an IP address of a domain or host on a network. | External |
path | View and modify the computers path location. | Internal |
pathping | View and locate locations of network latency. | External |
pause | Command used in batch files to stop the processing of a command. | Internal |
ping | Test / send information to another network computer or network device. | External |
popd | Changes to the directory or network path stored by the pushd command. | Internal |
power | Conserve power with computer portables. | External |
Prints data to a printer port. | External | |
prompt | View and change the MS-DOS prompt. | Internal |
pushd | Stores a directory or network path in memory so it can be returned to at any time. | Internal |
qbasic | Open the QBasic. | External |
rd | Removes an empty directory. | Internal |
ren | Renames a file or directory. | Internal |
rename | Renames a file or directory. | Internal |
rmdir | Removes an empty directory. | Internal |
robocopy | A robust file copy command for the Windows command line. | |
route | View and configure windows network route tables. | External |
runas | Enables a user to run a program as a different user. | External |
scandisk | Run the scandisk utility. | External |
scanreg | Scan registry and recover registry from errors. | External |
set | Change one variable or string to another. | Internal |
setlocal | Enables local environments to be changed without affecting anything else. | Internal |
setver | Change MS-DOS version to trick older MS-DOS programs. | External |
share | Installs support for file sharing and locking capabilities. | External |
shift | Changes the position of replaceable parameters in a batch program. | Internal |
shutdown | Shutdown the computer from the MS-DOS prompt. | External |
smartdrv | Create a disk cache in conventional memory or extended memory. | External |
sort | Sorts the input and displays the output to the screen. | External |
start | Start a separate window in Windows from the MS-DOS prompt. | Internal |
subst | Substitute a folder on your computer for another drive letter. | External |
switches | Remove add functions from MS-DOS. | Internal |
sys | Transfer system files to disk drive. | External |
telnet | Telnet to another computer / device from the prompt. | External |
time | View or modify the system time. | Internal |
title | Change the title of their MS-DOS window. | Internal |
tracert | Visually view a network packets route across a network. | External |
tree | View a visual tree of the hard disk drive. | External |
type | Display the contents of a file. | Internal |
undelete | Undelete a file that has been deleted. | External |
unformat | Unformat a hard disk drive. | External |
unlock | Unlock a disk drive. | Internal |
ver | Display the version information. | Internal |
verify | Enables or disables the feature to determine if files have been written properly. | Internal |
vol | Displays the volume information about the designated drive. | Internal |
xcopy | Copy multiple files, directories, or drives from one location to another. | External |
No comments:
Post a Comment