EXERCISE: 2 Using the ATTRIB Command

The ATTRIB command is used to set file attributes like making a file read-only or make it a hidden file. All the different file attributes is listed below:
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
If you are still in the MS-DOS Editor click on "File" and then on "Exit". If you followed along the Command Prompt should currently be "C:\MainDir\SubDir2>". If it is not the case use the CD or CD.. command to change it to "C:\MainDir\SubDir2>". Type Dir at the Command Prompt and make sure that the files "File2.txt" and "File2.dat" are present in this subdirectory. If it is not the case exactly repeat the steps explained in the "Editing Text Files" section. At the Command Prompt type Attrib +r File2.txt and press the "Enter" key. File2.txt should now be a read-only file. You can test this by typing Dir at the Command Prompt. Both "File2.txt" and "File3.dat" should now be listed. Now type Dir /ar at the Command Prompt and press "Enter". With this command entered like this only read-only files will be listed and you should now only see "File2.txt" listed.
Type Edit at the Command Prompt and click on "File" and then on "Open" in the MS-DOS Editor. Notice that the path beneath the "File Name" label should now be "C:\MainDir\SubDir2". If it is not the case set it by using the Directories box. Double-click on "File2.txt" to open it. Try to make some changes to the text in this file, but as you will see you will be notified that the file is read-only. If you should open this file in Notepad in Windows, you will see that you can make changes to it but you will not be allowed to save it under the same name. Exit the MS-DOS Editor now. At the Command Prompt type Attrib -r File2.txt and press the "Enter" key. The read-only attribute should now be removed from the file. If you open the file now with the MS-DOS Editor you will see that changes can be made and it can be saved. Exit the MS-DOS Editor by clicking on "File" and then on "Exit".
Under normal circumstances you should never have to use the "System File Attribute" as this is reserved for system files. Therefore the only other attribute that is worth mentioning is the "Hidden File Attribute". At the Command Prompt type Attrib +h File2.txt and press the "Enter" key. Type the Dir command and notice that "File2.txt" will not be listed. If you however type Dir /ah it will be possible to see this file as Dir /ah displays only hidden files. Likewise in Windows you will not be able to find the file if "Folder Options" is set to "Do not show hidden files and folders". If the "Folder Options" is set to "Show hidden files and folders" then you will be able to see the file even if its hidden attribute is set. At the Command Prompt type Attrib -h File2.txt to remove the hidden attribute.





The TYPE Command

The Type command is use to display the contents of text files on screen. At the moment the Command Prompt should still be at "C:\MainDir\SubDir2>". If not please change it accordingly. Type Type File2.txt at the Command Prompt and press "Enter". The contents of "File2.txt" should now be displayed. Well that is all there is to the Type command.


The COLOR Command
Let’s spice up the console display with some color. Use the COLOR command to set the default console foreground and background colors. Below is a list of hex digits that represents certain colors.
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

Type COLOR 8f at the command prompt and press the "Enter" key to set the console background color to aqua and the foreground color to bright white. To reset the console foreground and background colors to its default state just type COLOR without any argument at the command prompt and press the "Enter" key.


Moving Files

In the few examples that is going to follow we will make use of "wild cards" again when working with files to give you more insight into their use. Make sure the Command Prompt is currently "C:\MainDir\SubDir2>". If not use the CD or CD.. command to change it to "C:\MainDir\SubDir2>". At the Command Prompt type Move *.* C:\MainDir\SubDir1 to move the files to "SubDir1". Note how you had to specify the absolute path to Subdir1. Also note the use of wild cards. The *.* actually means All File Names with All Extensions should be moved to SubDir1. Type Dir at the Command Prompt and you will see that "File2.txt" and "File3.dat" is no longer present in "SubDir2".
To continue with the exercise we should change over to SubDir1. At the Command Prompt type CD.. which should move you back to "C:\MainDir>" and then type CD SubDir1 which should move you to the "C:\MainDir\SubDir1>" subdirectory. Type Dir at the Command Prompt and press "Enter". "File1.txt", "File2.txt" and "File3.dat" should now be present in "SubDir1".
At the Command Prompt type Move *.txt C:\MainDir\SubDir2 to move only the files with an .txt extension over to "SubDir2". When you do a directory listing with the Dir command you will notice that only "File3.dat" remains in the "SubDir1" subdirectory. Just a quick reminder, you do not have to use capital letters in your commands or in the path. I'm just doing it to make it more readable.


Copying Files

For the purpose of this exercise we have to be back in "SubDir2" so use the CD.. command and type "Enter" to get back to the "C:\MainDir>" parent directory. Now type CD SubDir2 to move to the "C:\MainDir\SubDir2>" subdirectory.
Use the Dir command and notice that "File1.txt" and "File2.txt" that you previously moved here with the Move command will be present. At the Command Prompt type Copy *.* C:\MainDir\SubDir1 to copy all the files in "SubDir2" over to "SubDir1". You also could have used Copy *.txt C:\MainDir\SubDir1 that would have had the same effect as these were the only files present in this subdirectory.
Type Dir at the Command Prompt and notice that because you used Copy instead of Move, both files will still be present in the "SubDir2" subdirectory.
We must now change over to "SubDir1". At the Command Prompt type CD.. which should move you back to "C:\MainDir>" and then type CD SubDir1 which should move you to the "C:\MainDir\SubDir1>" subdirectory. Type Dir at the Command Prompt and press "Enter". "File1.txt", "File2.txt" and "File3.dat" should now be present in "SubDir1" as "File1.txt" and "File2.txt" has been copied here with the Copy command.

Deleting Files With The DEL Command

Just a friendly reminder, take EXTREME care with the Del command as files deleted with this command is NOT GOING TO THE RECYCLE BIN and it can NOT BE RECOVERED.
Currently the Command Prompt should be at "C:\MainDir\SubDir1>". Type Del *.txt and use the Dir command to see the listing. Notice that all files with the .txt extension should have been deleted by the previous command. To delete the remaining file type Del File3.dat and do a directory listing again with the Dir command. There should be no remaining files.
Now we should change over to "SubDir2". Use the CD.. command to back down to the "C:\MainDir>" parent directory. Then use CD SubDir2 to move to the "C:\MainDir\SubDir2>" subdirectory. Do a Dir and notice that there is 2 files present in the subdirectory. Type Del *.* at the Command Prompt and do a Dir again. Notice when using the *.* wildcards together with the Del command that All File Names with All Extensions will be deleted which will be all files present in the current directory or subdirectory.
When using the *.* wildcards with the Del command the system might prompt you if you are sure. Just type a y or n which ever may be the case and press "Enter". If you previously forgot to remove the read-only attribute from "File2.txt" access will be denied if you try to delete this file. To fix that just type Attrib -r File2.txt at the Command Prompt and press "Enter". The Del command should now work without denying you access.

Deleting Directories (Folders) With The RD Command

As in the case when deleting files with the Del command, the same goes for when deleting Directories (Folders) with the RD command, please take EXTREME care with the RD command as Directories (Folders) deleted with this command is NOT GOING TO THE RECYCLE BIN and it can NOT BE RECOVERED.

If you currently are in the "C:\MainDir\SubDir2>" subdirectory use the CD.. command to back down to the "C:\MainDir>" parent directory.
Type RD SubDir1 and press "Enter" to delete the "SubDir1" subdirectory. To easily remember this command just think of RD as Remove Directory. Doing a Dir will reveal that "SubDir1' is deleted and only "SubDir2" remain. Proceed by typing RD SubDir2 to delete the "SubDir2" subdirectory.
Now type CD.. or CD\ to back down to the root of the drive. Type RD MainDir to delete the parent directory. Doing a Dir /p to see for you that it has been deleted. Just a quick reminder - the Dir /p is used to pause after every screen just in case the listing spans more than one screen.


Displaying or Setting The Date And Time

Type Date at the Command Prompt and press "Enter". The current date will be displayed and you are offered the option to change the system date. If you want to change the date be sure to follow the format as indicated. If you do not want to make changes to the system date just press the "Enter" key without entering a new date.
To view or set the system time type Time at the Command Prompt. Type the new system time in the indicated format and press "Enter". If you do not want to make changes to the system time just press "Enter" without entering new time information.


Batch Files

Batch files are a quick and efficient way to automate MS-DOS tasks or commands. Make sure the Command Prompt is currently in the root of C: (C Drive). It should display as follow: C:\> (If not Type CD\ at the Command Prompt and press "Enter")
Type Edit at the Command Prompt and press "Enter". In the MS-DOS Editor enter the following lines of text exactly as shown below with each command on a separate line. (Press the "Enter" key when at the end of a line).
MD MainDir
CD MainDir
MD SubDir1
MD SubDir2
In the MS-DOS Editor click on "File" then click on "Save". Next to the "File Name" label type "mybatch.bat" without the quotes in the "File Name" field and click on OK. Exit the MS-DOS Editor by clicking on "File" and then on "Exit".
At the Command Prompt type mybatch and press the "Enter" key. The batch file will execute and firstly create the "MainDir" directory in the root of the current drive. Then it will do a change directory to "C:\MainDir>". After that it will create "SubDir1" and "SubDir2" in the parent directory "MainDir" by using the MD (Make Directory) command. If you do a Dir now you will notice that you are already in the "MainDir" parent directory and the 2 created subdirectories is present. (Note that the names "MainDir", "SubDir1" and "SubDir2" I'm using is just to make explaining the exercises easier. You may use any name you desire.



Getting Help From DOS

I have covered by way of exercises the commands that will see you through with MS-DOS. Just in case you need more or quickly need info about one of the commands I've covered above, help is at hand directly from MS-DOS.
To get a listing of all MS-DOS commands type Help at the Command Prompt and press "Enter". Make sure the Command Prompt is not in full-screen mode otherwise you will not be able to see the complete listing. When not in full-screen mode you can use the scroll-bars at the right of the window to scroll up or down.
To get help for a specific command type CommandName help or type CommandName /? and press the "Enter" key. Below is some examples:
dir help
or
copy /?
Finally remember that you do not have to use capital letters to type out the commands.

The EXIT Command

To exit the Command Prompt session type Exit and press "Enter".

Final Word
It was quite a mouthful and I certainly hoped you've learned a lot. This was the knowledge I started of with and to learn it really helped me to appreciate how everything fit together. A lot of the knowledge you gained here will even help you to better understand Windows when you use it. In the Windows tutorials that will follow you will see how to accomplish the same tasks and knowing the MS-DOS way of doing it will really give you a better understanding of everything.





Followers