DOS Command Line


This entry is part 1 of 3 in the series DOS

In Windows, you can run DOS commands at the command line. In PC computers, DOS was the operating system in use before Windows came out. DOS has been around “forever”, but it’s still a great resource to have around. To open a command line on your Windows computer, right-click Start, click Run, type cmd, and press enter.

Why Use the DOS Command Line?

The short answer is that sometimes it is simply easier to use a DOS command than do something else. The hard part is remembering the syntax because we don’t normally use DOS every day. For example, do you need a list of files in a folder? Maybe you need this is a simple text file. For information on the dir command, you can go to Microsoft’s website and look at the dir article.

The script shown below is part of an actual session running DOS commands on my computer. I ran a cmd window in Windows and used Shift and the arrow keys to select the text. Then I used Ctrl+C to copy the text to the clipboard and pasted it into this post. Beforehand, I made a sample folder and files for this demonstration.

D:\temp>dir /b/a:-d
doc1.txt
document1.txt
file1.txt
file2.txt

D:\temp>dir /b/a:-d > filelist.txt

D:\temp>dir
 Volume in drive D is Data
 Volume Serial Number is 242C-7E01

 Directory of D:\temp

2020-09-25  07:12 PM    <DIR>          .
2020-09-25  07:12 PM    <DIR>          ..
2020-09-25  06:55 PM                18 doc1.txt
2020-09-25  06:56 PM                25 document1.txt
2020-09-25  06:56 PM            11,624 file1.txt
2020-09-25  06:55 PM               301 file2.txt
2020-09-25  07:12 PM                61 filelist.txt
2020-09-25  06:52 PM    <DIR>          subtemp
               5 File(s)         12,029 bytes
               3 Dir(s)  324,070,387,712 bytes free

D:\temp>type filelist.txt
doc1.txt
document1.txt
file1.txt
file2.txt
filelist.txt

D:\temp>

The dir command outputs to the screen a list of all of the folders and files in the current directory (folder). We use the /b parameter to only output the names of the files and directories. We use the /a parameter to specify certain attributes. It acts like a filter. The /d attribute specifies directories only. If we use -d we can specify not directories. If we use the > character we can redirect the output of the command. If we use > filelist.txt we can redirect the output of the dir command to the specified file filelist.txt in the current directory. At the end of the script we used the type command to display the contents of a file to the console (screen). You can also sort the output and include files from all subdirectories, among other things.

Popular DOS Commands

Here is a list of some popular DOS commands, other than dir.

  • cd – change directory either displays or changes the current working directory. – use cd .. to move up the directory tree.
  • copy – makes copies of existing files.
  • xcopy – Copy entire directory trees. Xcopy is a version of the copy command that can move files and directories from one location to another.
  • del – is used to delete one or more files.
  • move – Moves files or renames directories.
  • ren – The REN command renames a file. Unlike the move command, this command cannot be used to rename subdirectories, or rename files across drives.
  • deltree – Deletes a directory along with all of the files and subdirectories that it contains. Normally, it will ask for confirmation of the potentially dangerous action.
  • cls- The CLS or CLRSCR command clears the terminal screen.
  • md – Makes a new directory. The parent of the directory specified will be created if it does not already exist.
  • ver – returns the Windows version number.
  • help – returns several “pages” of help information.

To get the previous command, use the up arrow key.

Built-in Commands

The Windows command line comes with several built-in commands. For example, dir is a built-in command. There is no dir.exe program in Windows. It is a built-in command of cmd.exe. However, ipconfig is an external command. Below is a seesion at the command prompt that proves this.

C:\WINDOWS\system32>dir/s dir.exe
 Volume in drive C is Windows
 Volume Serial Number is 6E25-E9E0
File Not Found

C:\WINDOWS\system32>dir/s ipconfig.exe
 Volume in drive C is Windows
 Volume Serial Number is 6E25-E9E0

 Directory of C:\WINDOWS\system32

2019-03-18  11:45 PM            34,816 ipconfig.exe
               1 File(s)         34,816 bytes

     Total Files Listed:
               1 File(s)         34,816 bytes
               0 Dir(s)  15,597,506,560 bytes free

C:\WINDOWS\system32>

You might be interested in learning more. We have several posts on PowerShell at begincodingnow.com, staring with Windows PowerShell Introduction.

Series NavigationDOS Command to Append Text to a File >>