Due to popular demand and by popular demand I mean one person, I am going to do a similar post to what I did here about Linux bash commands. To be honest I don’t know why I didn’t think of it myself, it makes a lot of sense that if I am doing a post on good commands to know about for Linux then I should do a comparable one with MS-DOS. I used MS-DOS or DOS as it’s commonly called (I will refer to it as DOS from now on in this blog) in my previous job role where I was working for McDonald’s IT Department. Name drop there for you all =p
Unlike Linux, Dos commands are not case sensitive. So you can put caps where you like when writing the commands although it’s good practice to keep to either all upper or lower case. Personally I use all upper case when writing batch files but use lower case when operating with the command window. A weird personal preference of mine I guess. I am going to write them all in caps for this blog to show a different between these and the Linux ones, also it makes them a bit easy to read. This is by no means a definitive list, there are plenty of commands out there that do their own little things, I am merely going to once again talk about ones that I have found useful in the past. Since I have used these commands a lot more then I have used the Linux ones I can talk about them in a bit more detail and I will give some example commands and explain what they do.
So once again, without any more ado, here is the list that I have compiled;
ATTRIB = Displays or allows you to change file/directory attributes.
(R = Read Only, A = Archive, S = System File, H = Hidden File)
ATTRIB + = Sets and attribute.
ATTRIB – = Clears and Attribute.
Example Command: ATTRIB -R -H myfile.txt
What it does: Removes the read only and hidden file attributes from myfile.txt
CD = Change directory.
CD.. = Go up one directory level.
C: = Change to the C Drive
Example Command: X:
What it does: Will take my to my X Drive.
COLOR = Changes the background and text colour of the command window.
Explain Command: COLOR 0A (That is a zero followed by an A)
What it does: Will change the command window to have green text on a black background, so more of a matrix-y feel. There are plenty of other colours to choose from. Just type “COLOR /?” without the quotes into the window for more colours.
COPY CON = Create a new file.
Example Command: COPY CON myfile.txt
What it does: Creates a file called myfile.txt.
You should also note that when you use the COPY CON command after pressing enter the cursor will display on the next line, this is so you can write directly into the file. Once you have finished typing press CTRL+Z on your keyboard followed by the ENTER button.
CHDIR = Show current working directory.
DIR = Lists files and directories in your current working directory.Also display last modified date/time and whether it is a file or a directory.
DIR /b = Gives you just the names of the files/directories.
DIR /q = Displays the same as “dir” but with the owner of the file/directory.
DIR /s = Recursive display. List all subdirectories.
WARNING! – When using /s you might want to put the /p switch into the command line too as this pauses the output on the screen and allows you to manually advance by pressing any key. Without the /p switch you will find that the screen fills with text very quickly and is unreasonable.
DOSKEY /history = Outputs previous commands already typed into the command window.
ECHO = Displays messages. Used more in batch files then in the command line.
EXIT = Exit’s the current command window.
FIND = Search for a text string in a file or for files themselves. This command is case sensitive to what you type as the string.
Example Command: FIND “hello” myfile.txt
What it does: This command will find the string “hello” in the file myfile.txt. It will then output the line of text that the string is on. If there is more then one line with the word “hello” then it will output those lines as well.
FIND / i = Same as the above command but the string is not case sensitive.
FC = Shows differences in two files.
Example Command: FC myfile.txt test.txt
What it does: Shows you the difference between myfile.txt and test.txt.
IPCONFIG = Display currently assigned network settings such as IP Addresses.
IPCONFIG /all = Displays full configurations
IPCONFIG /release = Release the IP address for the current network adapter.
IPCONFIG /renew = Renew the IP address for the current network adapter.
HELP = Gives you a list of commands in dos with a brief description. Also, if you type the name of a command followed by a space and then “/?”, it will give you help on that specific command.
Example Command: HELP /?
What it does: This will output help on the help command to the command window.
MKDIR = Make a directory.
Example Command: MKDIR test
What it does: Will create a directory/folder called test.
MKLINK = Create links (symbolic links by default).
Example Command: MKLINK newlink.txt myfile.txt
What it does: Creates a symbolic link called newlink.txt from myfile.txt.
MKLINK /h = Hard link instead of symbolic. Hard links are similar to normal shortcuts.
Example Command: MKLINK /H newlink.txt myfile.txt.[
What it does: Creates a hard link called newlink.txt from myfile.txt.
MORE = Shows files a page at a time. This command is usually pipped into another command. If the output of the command it is being used with is going to fill the screen and more this command stops it once it fills the screen and then lets you advance through it at your own pace.
Example Command: IPCONFIG /ALL |MORE
What it does: This will output all the IP configuration information to the command screen but in parts rather then in one big text dump.
RMDIR = Remove a directory.
Example Command: RMDIR test
What it does: Will remove a directory/folder called test.
TASKLIST = Shows you a list of processes running at that moment in time.
TYPE = Display contents of files.
Example Command: TYPE myfile.txt
What it does: This command will output the contents of myfile.txt to the command window.
XCOPY = Allows you to copy files and directories.
XCOPY /s = Copies Subdirectories (except empty ones).
XCOPY /e = Copies Subdirectories including empty ones.
XCOPY /y = Copies files/directories without prompt. For example, it won’t ask to overwrite a file it will just go ahead and do it.
Example Command: XCOPY /Y myfile.txt C:USERADMINDESKTOP
What it does: This will take myfile.txt and copy it to the admin’s desktop. Also, if there is a file called myfile.txt already on the desktop of the admin user it will overwrite it without asking.
So that is the list for now. If you can think of any that should be added then please leave a constructive comment and I’ll see about adding it to the list.