Some Basic Commands of Command Prompt

1.cd\ Go to the top of the directory tree.

  • CD (Change Directory): Change the current folder or navigate to another folder.
C:\Users\LillianSIYIN>cd\
C:\>

2.cd.. Go back to one folder up.

C:\Users\LillianSIYIN>cd..
C:\Users>

3.e: Directly accesses to another drive (e drive).

C:\Users\LillianSIYIN>e:
E:\>

4.cd /d ... Changes the drive and the directory at the same time.

C:\Users\LillianSIYIN>cd /d e:\windows
E:\windows>

5.dir View the contents of a folder.

E:\SA>dir
   Volume in drive E has no label.
   Volume Serial Number is B8E7-1B00
   Directory of E:\SA
 03/30/2017  11:22 AM    <DIR>          .
 03/30/2017  11:22 AM    <DIR>          ..
 02/21/2017  02:33 PM       107,276,552 Enterprise Architecture.zip
 10/26/2016  08:15 PM    <DIR>          term1
 01/11/2017  05:48 PM    <DIR>          term2
 03/30/2017  11:22 AM    <DIR>          term3
               1 File(s)    107,276,552 bytes
               5 Dir(s)  35,814,080,512 bytes free
E:\SA>

6.mkdir ... or md ... (make directory) Creates a new folder or makes a new directory

C:\>md my_folder
C:\>

NOTE:

  • All these commands depend on the current location in the Command Prompt.
    Eg, if you are on the “C:” drive and type mkdir test, test will be created at “C:” drive.
  • Otherwise, is to type the complete path of the new folder.
    Eg, if you are at “C:” drive and you want to create my_folder in “E:”,type mkdir e:\my_folder.
C:\>md e:\my_folder
C:\>

7.ren ... (rename) Rename files and folders.

E:\SA>ren term1 TermOne
E:\SA>

8.copy ... ... Allow to copy files from one location to another.

You will receive a confirmation of the operation as below:

D:\Photos>copy IMG_0462.JPG e:\IMG_0462.JPG
        1 file(s) copied.

D:\Photos\about me>

NOTE: If you are copying within the same directory, don't have to put the path.

C:\Users\LillianSIYIN\Desktop>copy idea.docx idea.txt
        1 file(s) copied.

C:\Users\LillianSIYIN\Desktop>

9.xcopy /s /i ... ... (rename) Rename files and folders.

  • The /s parameter will ensure that all the directories and sub-directories will be copied, except the ones that are empty.
  • The /i parameter will create a new directory if the destination folder doesn't exist and will copy all the files.
E:\>xcopy /s /i e:\travel "c:\Users\LIN SIYIN\Desktop"\travel
E:\travel\abc.txt
1 File(s) copied
E:\>

10.del ... (delete) To delete all the files from the specified folder.

E:\>del travel
E:\travel\*, Are you sure (Y/N)? y
e:\>

NOTE:

  • To also delete hidden files from the folder, must add the /h parameter.
  • The del cammand doesn’t work for deleting the folder (view E:\>dir and E:\travel>dir):
E:\>dir
  Volume in drive E has no label.
  Volume Serial Number is B8E7-1B00
  Directory of E:\
04/05/2017  11:01 AM    <DIR>          OCBC
03/30/2017  11:27 AM    <DIR>          others
11/14/2016  03:41 PM                40 product key.txt
03/30/2017  11:22 AM    <DIR>          SA
04/05/2017  05:49 PM    <DIR>          travel
01/11/2017  05:54 PM    <DIR>          Unity
               1 File(s)             40 bytes
               5 Dir(s)  35,814,080,512 bytes free

E:\>cd travel
E:\travel>dir
 Volume in drive E has no label.
 Volume Serial Number is B8E7-1B00
 Directory of E:\travel
04/05/2017  05:49 PM    <DIR>          .
04/05/2017  05:49 PM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  35,814,080,512 bytes free

Some useful DEL combinations that are worth mentioning:

  1. DEL *.DOC - delete all .dco files (you can use any file extension);
  2. DEL Test*.* - delete all files beginning with Test;
  3. DEL *.* - delete ALL files from the current folder.

11.RD (remove directory) Delete the empty folder.

  • The RD command can only delete an empty folder.
E:\>RD travel
The directory is not empty.

E:\>del travel
E:\travel\*, Are you sure (Y/N)? y

E:\>RD travel

E:\>dir
 Volume in drive E has no label.
 Volume Serial Number is B8E7-1B00

 Directory of E:\

04/05/2017  11:01 AM    <DIR>          OCBC
03/30/2017  11:27 AM    <DIR>          others
11/14/2016  03:41 PM                40 product key.txt
03/30/2017  11:22 AM    <DIR>          SA
01/11/2017  05:54 PM    <DIR>          Unity
               1 File(s)             40 bytes
               4 Dir(s)  35,814,080,512 bytes free

E:\>

12.How to launch an application?

To run a program from the Command Prompt, you need only to navigate to the folder that contains the executable and type the program’s name.
For example, if you want to launch Paint , go to C:\Windows\System32 and you will find the executable called mspaint.exe. Then write mspaint.exe or simply mspaint and press Enter. Both commands and paint can be seen.

C:\Windows\System32>mspaint.exe
C:\Windows\System32>

13.How to get help in Command Prompt

  1. help A list with all available commands will be displayed:
C:\Windows\System32>help
For more information on a specific command, type HELP command-name
ASSOC          Displays or modifies file extension associations.
ATTRIB         Displays or changes file attributes.
BREAK          Sets or clears extended CTRL+C checking.
BCDEDIT        Sets properties in boot database to control boot loading.
CACLS          Displays or modifies access control lists (ACLs) of files.
CALL           Calls one batch program from another.
CD             Displays the name of or changes the current directory.
CHCP           Displays or sets the active code page number.
CHDIR          Displays the name of or changes the current directory.
CHKDSK         Checks a disk and displays a status report.
CHKNTFS        Displays or modifies the checking of disk at boot time.
CLS            Clears the screen.
CMD            Starts a new instance of the Windows command interpreter.
COLOR          Sets the default console foreground and background colors.
COMP           Compares the contents of two files or sets of files.
COMPACT        Displays or alters the compression of files on NTFS partitions.
CONVERT        Converts FAT volumes to NTFS.  You cannot convert the
               current drive.
COPY           Copies one or more files to another location.
DATE           Displays or sets the date.
DEL            Deletes one or more files.
DIR            Displays a list of files and subdirectories in a directory.
DISKPART       Displays or configures Disk Partition properties.
DOSKEY         Edits command lines, recalls Windows commands, and
               creates macros.
DRIVERQUERY    Displays current device driver status and properties.
ECHO           Displays messages, or turns command echoing on or off.
ENDLOCAL       Ends localization of environment changes in a batch file.
ERASE          Deletes one or more files.
EXIT           Quits the CMD.EXE program (command interpreter).
FC             Compares two files or sets of files, and displays the
               differences between them.
FIND           Searches for a text string in a file or files.
FINDSTR        Searches for strings in files.
FOR            Runs a specified command for each file in a set of files.
FORMAT         Formats a disk for use with Windows.
FSUTIL         Displays or configures the file system properties.
FTYPE          Displays or modifies file types used in file extension
               associations.
GOTO           Directs the Windows command interpreter to a labeled line in
               a batch program.
GPRESULT       Displays Group Policy information for machine or user.
GRAFTABL       Enables Windows to display an extended character set in
               graphics mode.
HELP           Provides Help information for Windows commands.
ICACLS         Display, modify, backup, or restore ACLs for files and
               directories.
IF             Performs conditional processing in batch programs.
LABEL          Creates, changes, or deletes the volume label of a disk.
MD             Creates a directory.
MKDIR          Creates a directory.
MKLINK         Creates Symbolic Links and Hard Links
MODE           Configures a system device.
MORE           Displays output one screen at a time.
MOVE           Moves one or more files from one directory to another
               directory.
OPENFILES      Displays files opened by remote users for a file share.
PATH           Displays or sets a search path for executable files.
PAUSE          Suspends processing of a batch file and displays a message.
POPD           Restores the previous value of the current directory saved by
               PUSHD.
PRINT          Prints a text file.
PROMPT         Changes the Windows command prompt.
PUSHD          Saves the current directory then changes it.
RD             Removes a directory.
RECOVER        Recovers readable information from a bad or defective disk.
REM            Records comments (remarks) in batch files or CONFIG.SYS.
REN            Renames a file or files.
RENAME         Renames a file or files.
REPLACE        Replaces files.
RMDIR          Removes a directory.
ROBOCOPY       Advanced utility to copy files and directory trees
SET            Displays, sets, or removes Windows environment variables.
SETLOCAL       Begins localization of environment changes in a batch file.
SC             Displays or configures services (background processes).
SCHTASKS       Schedules commands and programs to run on a computer.
SHIFT          Shifts the position of replaceable parameters in batch files.
SHUTDOWN       Allows proper local or remote shutdown of machine.
SORT           Sorts input.
START          Starts a separate window to run a specified program or command.
SUBST          Associates a path with a drive letter.
SYSTEMINFO     Displays machine specific properties and configuration.
TASKLIST       Displays all currently running tasks including services.
TASKKILL       Kill or stop a running process or application.
TIME           Displays or sets the system time.
TITLE          Sets the window title for a CMD.EXE session.
TREE           Graphically displays the directory structure of a drive or
               path.
TYPE           Displays the contents of a text file.
VER            Displays the Windows version.
VERIFY         Tells Windows whether to verify that your files are written
               correctly to a disk.
VOL            Displays a disk volume label and serial number.
XCOPY          Copies files and directory trees.
WMIC           Displays WMI information inside interactive command shell.

For more information on tools see the command-line reference in the online help.

C:\Windows\System32>
  1. Type help followed by the name of that command or type the command’s name followed by the /? parameter: Looking into a specified command.
C:\Windows\System32>help cd
Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]

  ..   Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.

Use the /D switch to change current drive in addition to changing current
directory for a drive.

If Command Extensions are enabled CHDIR changes as follows:

The current directory string is converted to use the same case as
the on disk names.  So CD C:\TEMP would actually set the current
directory to C:\Temp if that is the case on disk.

CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes.  For example:

    cd \winnt\profiles\username\programs\start menu

is the same as:

    cd "\winnt\profiles\username\programs\start menu"

which is what you would have to type if extensions were disabled.

C:\Windows\System32>

or

C:\Windows\System32>copy /?
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
     [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

  source       Specifies the file or files to be copied.
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  /D           Allow the destination file to be created decrypted
  destination  Specifies the directory and/or filename for the new file(s).
  /V           Verifies that new files are written correctly.
  /N           Uses short filename, if available, when copying a file with a
               non-8dot3 name.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.
  /L           If the source is a symbolic link, copy the link to the target
               instead of the actual file the source link points to.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).

C:\Windows\System32>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容