MS-DOS Shell Basic [Working with directories]


DOS COMMAND

1. The Directory Tree
Every disk has at least one directory. When you format a floppy or hard disk, MS-DOS creates a directory where all other files and directories will be stored. This is called the root directory. You can create subdirectories of the root directory to organize files.
 
For example, you could put your files in one directory and your image files in another. Directories and subdirectories form structure called a directory tree, as in the following example:


You can create subdirectories within subdirectories to further organize your files. Your directory structure would resemble the following:
You can continue to add directories at any level of the structure.

2.Viewing Whole Directories
To view the contents of a directory, use the dir command. For example, you could use the following command to view the contents of the C:\WINDOWS directory:
            dir c:\windows

The dir command (without parameters) lists the contents of the current directory. For example, if C:\ is your current directory, you can use the following command to view its contents:

            dir
MS-DOS displays a listing similiar to the following:

If you add the path of a directory to the command, MS-DOS displays the contents of specified directory rather than the current directory. Regardless of which directory is current, you would use the following command to view a list of files in the root directory of a disk in drive E:
     dir e:\
To view the filenames listed in a subdirectory, you can specify the path relative to the current directory, or you can specify the entire path. For example, if C:\WINDOWS is you current directory and you want to view the contents of the C:\WINDOWS\SYSTEM32 directory, you could type the following command:
     dir system32

3.Viewing Groups of Filenames
To view a group of filenames in a directory listing, include wilcards with the dir command. For example, you would use the following command to view a list of all files that have a .COM extension in the current directory:
     dir *.com
Unless you specify otherwise, MS-DOS displays all filenames and subdirectory names in a directory. To view only certain filenames in a directory, you can use wildcards. For example, to see a list of files that a .DOC extension in the root directory of a disk in drive D, type the following command:
     dir d:\*.doc
To view the filenames beginning with WORK in a subdirectory called DOC on drive D, type this command:
     dir d:\doc\work*.*

4. Viewing Group of File Extension On a Disk
To view a group of file extension on a disk, use the /s switch. For example, if C:\ is your current directory, you can use the following command to view specific file extension:
     dir /s *.doc

you can see the results as shown below

5. Arranging the Directory Display
To view the contents of a directory one screen at a time, use the /p switch, as in the following command:
     dir c:\windows /p

To view an abbreviated directory, with only directory names and filenames listed, use the /w switch:
     dir c:\windows /w

6. Sorting a Directory Listing
To sort a directory listing by filename (n), extension (e), date (d), or file size (s), use the /o switch. For example, the following command alphabetizes a directory listing by filename extension:
     dir c:\windows /oe
This command alphabetizes a directory listing in reverse alphabetic order (from Z to A):
     dir c:\windows /o-e

MS-DOS sorts a directory listing when you include the /o switch. The following list shows the various ways of using the /o switch to sort a directory listing:

            /on   Alphabetizes the directory by name
            /o-n  Reverse-alphabetizes the directory by name (Z to A)
            /oe   Alphabetizes the directory by extension
            /o-e  Reverse-alphabetizes the directory by extension (Z to A)
            /od   Sorts the directory by date (oldest first)
            /o-d  Sorts the directory by date (newest first)
            /os   Orders the directory by file size (smallest first)
            /o-s  Order the directory by file size (largest first)

For example, the following command displays the contents of the current directory of a disk in drive C, largest file first:
     dir c: /o-s

You can also combine switches to get the results you want. For example, the following command alphabetizes the listing of the root directory on the C drive:
     dir c:\ /on /w

7. Viewing All Directories on a Disk
To view the organization of a directory and its subdirectories, use the tree command. For example, the following command displays the relationship between the C:\WINDOWS directory and its subdirectories:
     tree c:\windows

In the following command, the /f switch is used to include filenames:
     tree /f

8. Creating Directories
To create a directory, use the md (mkdir) command. The following command command creates a new subdirectory called ABC
           md abc

9. Changing Directories
To move to a different directory on the current drive, use the cd (chdir) command. You can also use two periods (..) after the cd command to change to the parent directory, as follow:
           cd ..

10. Deleting Directories
To delete a directory, use rd (rmdir) command, as in the following example:
           rd \abc\xyz\123

If you no longer need a directory, you can remove it by using the rd command. In order for you to remove a directory, it must be empty and it cannot be the current directory. For example, before you can remove a directory called \ABC, which does not contain any subdirectories, you must delete its contents. To do so, you can type the following command:
     del \ABC\*.*

You can then type the following command to remove the directory:
     rd abc

11. Copying Directories
To copy directory and its subdirectories, you can use the xcopy command.
     xcopy c:\abc\xyz\123 a:\123

12. Creating Directories as You Copy Files
If the destination path in an xcopy command does not exist, MS-DOS creates it. For example, the following command copies all files from the root directory of a disk in drive A to the C:\TMP directory:
     xcopy a:\ c:\tmp

13. Copying Subdirectories
To reproduce an entire directory structure in another directory or on another disk, use the /s and /e switches. For example, the following command recreates on a disk in drive D the directory structure and files in C:\ABC:
     xcopy c:\abc d:\ /s /e
 


Keyword: DOS Shell | MS-DOS Operating System | Using the Command Line | Run MS-DOS Commands | MS-DOS Commands | MS-DOS Operating System | ms-dos win 7

You may also like: