Using CmdThis is a featured page

Cmd Commands guide written by Canakar

What is Command Prompt?
_____________________________
------------------------

The Command Prompt program allows you to work in an environment that looks more like a traditional operating system as opposed to the icon based Windows environment. In Command Prompt, you will use your keyboard. You won't use your mouse at all. Command Prompt works at a lower level than Windows. This means that you will have more control over the machine. The disadvantage is that it is less user-friendly.

You will need the command prompt in COS 126 to compile and execute your Java programs. Learning the Command Prompt also provides a gradual transition to Unix and Linux systems, which are prevalent in science, engineering, and industry.

To launch Command Prompt select Start -> Run and type cmd in the box.

The Command Prompt shows up as a black terminal window. The command prompt should look something like:

C:\>

This is where you type commands. The boldface type below (that follows the command prompt) is what you should type as you work through this tutorial. Windows does not care if you use upper or lower case. That means that command cd is the same as CD. It also means that, in Windows, file HelloWorld.java is the same as helloworld.java. This is NOT true in the system to which you will be submitting your files. Be very careful!!!


MS-Dos Commands.
_____________________________________________
ADDUSERS Add or list users to/from a CSV file
ARP Address Resolution Protocol
ASSOC Change file extension associations
ASSOCIAT One step file association
AT Schedule a command to run at a later time
ATTRIB Change file attributes
_____________________________________________
BOOTCFG Edit Windows boot settings
BROWSTAT Get domain, browser and PDC info
_____________________________________________
CACLS Change file permissions
CALL Call one batch program from another
CD Change Directory - move to a specific Folder
CHANGE Change Terminal Server Session properties
CHKDSK Check Disk - check and repair disk problems
CHKNTFS Check the NTFS file system
CHOICE Accept keyboard input to a batch file
CIPHER Encrypt or Decrypt files/folders
CleanMgr Automated cleanup of Temp files, recycle bin
CLEARMEM Clear memory leaks
CLIP Copy STDIN to the Windows clipboard.
CLS Clear the screen
CLUSTER Windows Clustering
CMD Start a new CMD shell
COLOR Change colors of the CMD window
COMP Compare the contents of two files or sets of files
COMPACT Compress files or folders on an NTFS partition
COMPRESS Compress individual files on an NTFS partition
CON2PRT Connect or disconnect a Printer
CONVERT Convert a FAT drive to NTFS.
COPY Copy one or more files to another location
CSVDE Import or Export Active Directory data
_____________________________________________
DATE Display or set the date
Dcomcnfg DCOM Configuration Utility
DEFRAG Defragment hard drive
DEL Delete one or more files
DELPROF Delete NT user profiles
DELTREE Delete a folder and all subfolders
DevCon Device Manager Command Line Utility
DIR Display a list of files and folders
DIRUSE Display disk usage
DISKCOMP Compare the contents of two floppy disks
DISKCOPY Copy the contents of one floppy disk to another
DNSSTAT DNS Statistics
DOSKEY Edit command line, recall commands, and create macros
DSADD Add user (computer, group..) to active directory
DSQUERY List items in active directory
DSMOD Modify user (computer, group..) in active directory
________________________________________________
ECHO Display message on screen
ENDLOCAL End localisation of environment changes in a batch file
ERASE Delete one or more files
EXIT Quit the CMD shell
EXPAND Uncompress files
EXTRACT Uncompress CAB files
__________________________________________
FC Compare two files
FDISK Disk Format and partition
FIND Search for a text string in a file
FINDSTR Search for strings in files
FOR Conditionally perform a command several times
FORFILES Batch process multiple files
FORMAT Format a disk
FREEDISK Check free disk space (in bytes)
FSUTIL File and Volume utilities
FTP File Transfer Protocol
FTYPE Display or modify file types used in file extension associations
______________________________________________
GLOBAL Display membership of global groups
GOTO Direct a batch program to jump to a labelled line
______________________________________________
HELP Online Help
HFNETCHK Network Security Hotfix Checker
______________________________________________
IF Conditionally perform a command
IFMEMBER Is the current user in an NT Workgroup
IPCONFIG Configure IP
______________________________________________
KILL Remove a program from memory
______________________________________________
LABEL Edit a disk label
LOCAL Display membership of local groups
LOGEVENT Write text to the NT event viewer.
LOGOFF Log a user off
LOGTIME Log the date and time in a file
______________________________________________
MAPISEND Send email from the command line
MEM Display memory usage
MD Create new folders
MODE Configure a system device
MORE Display output, one screen at a time
MOUNTVOL Manage a volume mount point
MOVE Move files from one folder to another
MOVEUSER Move a user from one domain to another
MSG Send a message
MSIEXEC Microsoft Windows Installer
MSINFO Windows NT diagnostics
MSTSC Terminal Server Connection (Remote Desktop Protocol)
MUNGE Find and Replace text within file(s)
MV Copy in-use files
________________________________________________
NET Manage network resources
NETDOM Domain Manager
NETSH Configure network protocols
NETSVC Command-line Service Controller
NBTSTAT Display networking statistics (NetBIOS over TCP/IP)
NETSTAT Display networking statistics (TCP/IP)
NOW Display the current Date and Time
NSLOOKUP Name server lookup
NTBACKUP Backup folders to tape
NTRIGHTS Edit user account rights
________________________________________________
PATH Display or set a search path for executable files
PATHPING Trace route plus network latency and packet loss
PAUSE Suspend processing of a batch file and display a message
PERMS Show permissions for a user
PERFMON Performance Monitor
PING Test a network connection
POPD Restore the previous value of the current directory saved by PUSHD
PORTQRY Display the status of ports and services
PRINT Print a text file
PRNCNFG Display, configure or rename a printer
PRNMNGR Add, delete, list printers set the default printer
PROMPT Change the command prompt
PsExec Execute process remotely
PsFile Show files opened remotely
PsGetSid Display the SID of a computer or a user
PsInfo List information about a system
PsKill Kill processes by name or process ID
PsList List detailed information about processes
PsLoggedOn Who's logged on (locally or via resource sharing)
PsLogList Event log records
PsPasswd Change account password
PsService View and control services
PsShutdown Shutdown or reboot a computer
PsSuspend Suspend processes
PUSHD Save and then change the current directory
_______________________________________________
QGREP Search file(s) for lines that match a given pattern.
_______________________________________________
RASDIAL Manage RAS connections
RASPHONE Manage RAS connections
RECOVER Recover a damaged file from a defective disk.
REG Read, Set or Delete registry keys and values
REGEDIT Import or export registry settings
REGSVR32 Register or unregister a DLL
REGINI Change Registry Permissions
REM Record comments (remarks) in a batch file
REN Rename a file or files.
REPLACE Replace or update one file with another
RD Delete folder(s)
RDISK Create a Recovery Disk
RMTSHARE Share a folder or a printer
ROBOCOPY Robust File and Folder Copy
ROUTE Manipulate network routing tables
RUNAS Execute a program under a different user account
RUNDLL32 Run a DLL command (add/remove print connections)
__________________________________________________ _
SC Service Control
SCHTASKS Create or Edit Scheduled Tasks
SCLIST Display NT Services
ScriptIt Control GUI applications
SET Display, set, or remove environment variables
SETLOCAL Begin localisation of environment changes in a batch file
SETX Set environment variables permanently
SHARE List or edit a file share or print share
SHIFT Shift the position of replaceable parameters in a batch file
SHORTCUT Create a windows shortcut (.LNK file)
SHOWGRPS List the NT Workgroups a user has joined
SHOWMBRS List the Users who are members of a Workgroup
SHUTDOWN Shutdown the computer
SLEEP Wait for x seconds
SOON Schedule a command to run in the near future
SORT Sort input
START Start a separate window to run a specified program or command
SU Switch User
SUBINACL Edit file and folder Permissions, Ownership and Domain
SUBST Associate a path with a drive letter
SYSTEMINFO List system configuration
____________________________________________
TASKLIST List running applications and services
TIME Display or set the system time
TIMEOUT Delay processing of a batch file
TITLE Set the window title for a CMD.EXE session
TOUCH Change file timestamps
TRACERT Trace route to a remote host
TREE Graphical display of folder structure
TYPE Display the contents of a text file
____________________________________________
USRSTAT List domain usernames and last login
____________________________________________
VER Display version information
VERIFY Verify that files have been saved
VOL Display a disk label
____________________________________________
WHERE Locate and display files in a directory tree
WHOAMI Output the current UserName and domain
WINDIFF Compare the contents of two files or sets of files
WINMSD Windows system diagnostics
WINMSDP Windows system diagnostics II
WMIC WMI Commands
____________________________________________
XCACLS Change file permissions
XCOPY Copy files and folders


Command Prompt Basics
_________________________
------------------------

When you are working in Command Prompt, there are a couple of things that usually work:

Many of the commands will have extra options available, known as switches. They are added to the command by entering a "/" then a letter, number or word. These can change how the tool works or handles the information. A common switch would be the help command, which will also give you information on the other switches available.

<command> /?
This would usually brings up information and about the command and the available switches. If it doesn't work, try "-?" after the command instead.

<command> > <filename>.txt
This will send the results of the command to a text file instead of the screen. You can include switches as well. This is particularly useful if you are looking at the help information for a command. Look at this example command:

xcopy /? >c:\xcopy.txt

This writes the content of the help command to a file called xcopy.txt located in the root of the C:\ drive.

CLS
If you have lots of text in your Command Prompt window, this command will clear it.




Working with Files and Directories
__________________________
----------------------


You can also use Command Prompt commands to organize files into a directory hierarchy. These commands are equivalent to corresponding commands that you access via the Windows point-and-click interface. It is useful to be familiar with both interfaces for managing files.

* dir: To view the contents of a directory, type dir. This command will list all the files and directories within the current directory. It is analogous to clicking on a Windows folder to see what's inside.

C:\> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\

10/26/2004 01:36 PM 0 AUTOEXEC.BAT
10/26/2004 01:36 PM 0 CONFIG.SYS
02/10/2005 01:36 PM 126 HelloWorld.java
12/09/2004 12:11 AM DIR Documents and Settings
02/10/2005 08:59 PM DIR introcs
11/02/2004 08:31 PM DIR j2sdk1.4.2_06
12/29/2004 07:15 PM DIR Program Files
01/13/2005 07:33 AM DIR WINDOWS
3 File(s) 126 bytes
5 Dir(s) 32,551,940,096 bytes free

There are 7 items in this directory. Some of them are files, like HelloWorld.java. Others are directories, like introcs.

* cd: It is frequently useful to know in which directory you are currently working. In order to find out, type cd at the command prompt.

C:\> cd
C:\

To change directories, use the cd command with the name of a directory.

C:\> cd introcs

Now, the command prompt will be:

C:\introcs>

To see what is in this directory type:

C:\introcs> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
2 Dir(s)

To return to the previous directory, use the cd command, but this time followed by a space and two periods.

C:\introcs> cd ..
C:\>

* mkdir: To create a new directory, use the command mkdir. The following command creates a directory named hello, which you can use to to store all of your files associated with the Hello World assignment.

C:\introcs> mkdir hello

To see that it actually worked, use the dir command.

C:\introcs> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/11/2005 02:53 PM DIR hello
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
3 Dir(s)

* move: Now, move the two files HelloWorld.java and readme.txt into the hello directory using the move command.

C:\introcs> move HelloWorld.java hello
C:\introcs> move readme.txt hello
C:\introcs> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/11/2005 02:53 PM DIR hello
0 File(s) 0 bytes
3 Dir(s)

The two files are no longer visible from the current directory.

To access the two files, change directories with the cd command. Then use the dir command to see what is in this new directory.

C:\introcs> cd hello
C:\introcs\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs\hello

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
2 Dir(s)

You can also use move to rename a file. Simply specify a new filename instead of a directory name. Suppose you accidentally messed up the upper and lower case and had saved HelloWorld.java as helloworld.java. Use two move commands to fix it.

C:\introcs\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs\hello

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 helloworld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
2 Dir(s)

C:\introcs\hello> move helloworld.java temp.java
C:\introcs\hello> move temp.java HelloWorld.java
C:\introcs\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs\hello

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
2 Dir(s)


It takes two moves because Windows won't let you move to an already existing filename and, to Windows, helloworld.java is the same as HelloWorld.java.

* copy: To make a copy of a file, use the copy command. The following command creates a backup copy of our HelloWorld.java program. This is especially useful when you modify a working program, but might want to revert back to the original version if your modifications don't succeed.

C:\introcs\hello> copy HelloWorld.java HelloWorld.bak
C:\introcs\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs\hello

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
3 Dir(s)

* del: Subsequently, you might want to clean up useless files. The del command deletes a file.

C:\introcs\hello> del HelloWorld.bak
C:\introcs\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD

Directory of C:\introcs

02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 HelloWorld.java
01/17/2005 01:16 AM 256 readme.txt
2 File(s) 382 bytes
3 Dir(s)

WARNING: When you revise a file in jEdit, the jEdit program will automatically save a backup copy of your original file in the same directory. The name of the backup file will be the name of the original file with a ~ at the end. When you submit your program be careful to submit HelloWorld.java and not HelloWorld.java~ which is an old version of the file and has the wrong name.
* wildcards: You can also apply the copy, del, and move commands to several files (or directories) at once. To create a new directory called loops, and copy all of the files in the hello directory C:\introcs\hello\ into this newly created directory type:

C:\introcs> mkdir loops
C:\introcs> copy c:\introcs\hello\* loops

Here the * matches all files in the C:\introcs\hello directory. It copies them to your newly created loops directory.

Redirection
____________
---------

Two important abstractions in Command Prompt are standard input and standard output. By default standard input is your keyboard, and standard output is your computer screen. For example, in Assignment 1, we write a program CenterofMass.java that reads input using StdIn.java and writes output using System.out.println(). To run our program, the user types the command "java CenterofMass" and enters double type values in triplets: xposition yposition mass from the keyboard. The results appear in the terminal window.

C:\introcs\loops> java CenterofMass
0 0 10
1 1 10
0.5 0.5 20

* Redirecting standard input. As an alternative, we can create a file that consists of the same six input numbers. Using a text editor (like jEdit), create a file named input.txt, and type in the six numbers. After saving the file in the loops directory, type the following command to verify that you entered the integers correctly:

C:\introcs\loops> more input.txt
0 0 10
1 1 10

Then to read the integers from the file instead of the keyboard, we use the redirection symbol "<".

C:\introcs\loops> java CenterofMass < input.txt
0.5 0.5 20

This produces exactly the same result as if the user had typed the numbers, except that the user has no opportunity to enter numbers from the keyboard. This is especially useful for two reasons. First, if there are lots of input values (there are over 700 inputs for Assignment 2) it would be tedious to retype them in each time we run our program. Second, it allows programs to be automated, without waiting for user interaction. This means that your grader can process your homework programs without typing in the input values by hand each time.
* Redirecting standard output. Similarly it is possible to redirect the output to a file instead of to the screen. Continuing with the same example, if we want to save the output permanently, we can use the output redirection symbol '>'.

C:\introcs\loops> java CenterofMass > output.txt
0 0 10
1 1 10

The user still types in the input values from the keyboard, but instead of sending the output to the screen, it is sent to the file named output.txt. Note that all printf output is sent to the file, even the statement that tells the user what to do. Be careful, if the file output.txt already exists, it will be overwritten. (To append use '>>' instead.)

phoenix.Princeton.EDU% more output.txt

* Redirecting standard input and standard output. It is often useful to use both redirection operations simultaneously.

C:\introcs\loops> java CenterofMass < input.txt > output2.txt

After executing this command, no output appears on the screen, but the file output2.txt now contains exactly the same data as output.txt above.


Piping
_______
-----

Another useful abstraction is piping. Piping is when the output of one program is used as the input of another program. For example, suppose we want to view the output of a program, but there is so much that it whizzes by on the screen too fast to read. (The program RandInts.java prints out a bunch of random integers.) One possible way to accomplish this is to type the following two commands.

C:\introcs> java RandInts > temp.txt
C:\introcs> more < temp.txt

Note that more will work by redirecting the file temp.txt to standard input (as is done here) or by simply using the filename (as is done at the beginning of the document). Instead, we could do this in one line using the pipe symbol '|'

C:\introcs> java RandInts | more

This is often useful when debugging a program, especially if your program goes into an infinite loop and you want to see the first few values that it prints


No user avatar
Canakar
Latest page update: made by Canakar , Feb 19 2009, 12:32 AM EST (about this update About This Update Canakar Edited by Canakar

No content added or deleted.

- complete history)
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)