DOS Command are used to interact with the operating system. There are many commands available as internal and external to do many tasks/operations. The users who use windows OS can type cmd in the task bar to get command prompt where They can type commands to interact with OS.
C:\>cmd
MS-DOS was the first operating system designed and released by Microsoft for IBM, IBM compatible personal computers during the 1980s. Even today these commands are ease many tasks in Windows Environment too. There are two types of command available.
- Internal Command: Internal commands are built-in commands of MS-DOS, stored in the command interpreter "COMMAND.COM". These commands reside in memory if the system is at prompt "C:\>"
- External Command: External commands are separate program (.com, .exe) files that reside in the DOS directory. eg: format.com, tree.com, attrib.exe etc.
This blog will help to understand some frequently used internal DOS command with examples.
Clear the screen
C:\>CLS Clears the screen.
Displays or sets the date
C:\>date The current date is: Wed 11/17/2021 Enter the new date: (mm-dd-yy) Displays or sets the date.
Displays or sets the Time
C:\>time The current time is: 23:59:29.08 Enter the new time:
Create new Directory
MD [drive:]path c:\>md Pascal create a folder called 'Pascal' in 'C:\' c:\>md temp create a folder called 'temp' in 'C:\' c:\Pascal>md program create a subfolder 'program' in the folder 'C:\Pascal'
Change the current folder
CD [/D] [drive:][path] C:\>cd Pascal The above command will change the current root to Pascal folder c:\Pascal>cd program The above command will change the current 'C:\Pascal' folder to subfolder 'C:\Pascal\program' c:\Pascal\Program>cd.. the above command will change the current subfolder to parent folder Pascal C:\Pascal> C:\Pascal\Program>Cd\ the above command will change the current to root of c. C:\
Remove a folder
RD [/S] [/Q] [drive:]path c:\Pascal>RD program The above command will remove the subfolder program in the Pascal folder (The program folder should be empty and instruction should be given from parent folder of program)
Display Files and Folders
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] Display the list of files and subdirectories in a directory. C:\>dir /P Display by page pause C:\dir /W Display as wide list format C:\>dir /OD Display by date order C:\>dir /OS Display by file size C:\>dir /OE Display by Extensions C:\>dir /AR Display read only files C:\>dir /AH Display hidden files C:\>dir /B Display as bare format
Using wild card Operators ('*' for all and '?' for unknown character) with DIR command
C:\>dir *.txt Display all the files with the extension 'txt' in c:\ C:\>dir A*.* Display all the files which have 'A' as first character of its file name in C:\. C:\>dir *.p* Display all the files which have 'p' as first character of the extension in C:\ C:\>dir ?A*.* Display all the files which have 'A' as second character its filename in C:\
Create a Text files
c:\>copy con abc.txt This is the content of this file. <ctrl>+Z The above command will create a file called 'abc.txt' and its content will be 'This is the content of this file.'. <ctrl>+Z will be used to end the input and save the files. Display the content of a text file C:\>type abc.txt The above command will display the content of the text file abc.txt Rename a file REN [drive:][path] oldname newname C:\>ren abc.txt xyz.txt The above command will rename the abc.txt file as xyz.txt Delete a file/ files DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names C:\>del xyz.txt The above command will delete a file xyz.txt We can use wild card operators with del command too. C:\>del *.txt The above command will delete all the files with the extension 'txt' C:\>del A*.* The above command will delete all the files which first character of filename is 'A' Copy a file/ files COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]] C:\>copy pqr.txt c:\temp Copy the pqr.txt file from the c:\ to the destination folder c:\temp C:\>copy *.* c:\temp Copy all the files form 'c:\' to the folder 'c:\temp' c:\program>copy *.pas c:\Pascal Copy all the files from 'c:\program' folder to 'c:\pascal' folder C:\>
Change Prompt Color
COLOR [--] -- TWO hex digits, the first corresponds to the background; the second the foreground. Each Hex digit define below colors. 0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow C:\>color 4 Change the prompt with foreground color red. C:\>color 61 Change the prompt with foreground color yellow and background blue.
DOS Exercise
Question
You have a folder called programs in 'c:\' (root) which contains files of Java, Pascal programs. Do the below tasks using DOS Commands.
- Change the Directory to 'c:\programs'
- List and Check all the files which are available in 'c:\programs' folder
- Create two separate subfolders called 'Java' and 'Pascal' in the 'Programs' folder
- Copy all the java program files into 'Java' subfolder
- Copy all the pascal programs into 'Pascal' subfolder
- Delete all the files in the programs folder.
Answer
C:\>cd programs C:\programs>dir Volume in drive C is Windows Volume Serial Number is 6668-1FA8 Directory of C:\programs 11/18/2021 12:24 AM <DIR> . 11/18/2021 12:24 AM <DIR> .. 11/18/2021 12:23 AM 7 circle.java 11/18/2021 12:23 AM 4 class.java 11/18/2021 12:23 AM 4 ex1.java 11/18/2021 12:22 AM 4 ex1.pas 11/18/2021 12:23 AM 6 ex2.java 11/18/2021 12:22 AM 4 ex2.pas 11/18/2021 12:22 AM 6 ex3.pas 11/18/2021 12:22 AM 5 main.pas 11/18/2021 12:24 AM 4 rect.java 11/18/2021 12:22 AM 7 test.pas 10 File(s) 51 bytes 2 Dir(s) 157,863,772,160 bytes free C:\programs>cd.. C:\>cd programs C:\programs>md Pascal C:\programs>md Java C:\programs>copy *.pas c:\programs\Pascal ex1.pas ex2.pas ex3.pas main.pas test.pas 5 file(s) copied. C:\programs>copy *.java c:\programs\java circle.java class.java ex1.java ex2.java rect.java 5 file(s) copied. C:\programs>del *.* C:\programs\*.*, Are you sure (Y/N)? y C:\programs>dir Volume in drive C is Windows Volume Serial Number is 6668-1FA8 Directory of C:\programs 11/18/2021 12:27 AM <DIR> . 11/18/2021 12:27 AM <DIR> .. 11/18/2021 12:26 AM <DIR> Java 11/18/2021 12:26 AM <DIR> Pascal 0 File(s) 0 bytes 4 Dir(s) 157,863,612,416 bytes free C:\programs>cd java C:\programs\Java>dir Volume in drive C is Windows Volume Serial Number is 6668-1FA8 Directory of C:\programs\Java 11/18/2021 12:26 AM <DIR> . 11/18/2021 12:26 AM <DIR> .. 11/18/2021 12:23 AM 7 circle.java 11/18/2021 12:23 AM 4 class.java 11/18/2021 12:23 AM 4 ex1.java 11/18/2021 12:23 AM 6 ex2.java 11/18/2021 12:24 AM 4 rect.java 5 File(s) 25 bytes 2 Dir(s) 157,863,612,416 bytes free C:\programs\Java>cd.. C:\programs>tree Folder PATH listing for volume Windows Volume serial number is 6668-1FA8 C:. ├───Java └───Pascal C:\programs>
No comments:
Post a Comment