CMD Command line basis

(I) the definition of

cmd command is an abbreviation that is the command prompt (CMD), is in OS / 2, Win-based operating systems (including Windows 2000 and XP, Vista in, and Server 2003) "MS-DOS mode" under. Chinese version of Windows XP in command prompt to further improve compatibility with the DOS operating commands, the user can enter the Chinese call the file directly in the command prompt.

 

(Ii) the role of command and run operations

Role: information inquiry system or network is good or bad judgment

Operation: CMD command: Start -> Run -> type cmd or command (in the command line you can see the system version, file system version)

 

(Iii) basic commands

1) Windows, there are two commands: internal commands and external commands. I.e., internal commands in the command line interpreter built-in commands, no additional procedures, such as dir, copy and the like. External command in the form of an executable file (usually exe extension or com) exists on disk, which means that the program must exist, otherwise Windows can not find the command, such as format.com.

2) after each command to be input Enter, side running, and to obtain the results. Command line interpreter between the string prompt ">" and Enter regarded as one command. If this string is indeed consistent with the Windows command syntax to execute it, it went back after the implementation of prompt or the command line interpreter gives an error message.

3) To learn a command, the best way is to read the command-line help. You can enter "command name /?" Or "help command name" to view online help commands, such as "format /?".

 

 

 Note: Back up to the time on a return path to the root, as in D: can not back up the \ path.
 Another: You can enter a part of when you enter the folder name, press the Tab key completion

 

(Iv) directory operations command

1. md (Make Directory): Create a directory.

MKDIR [drive:]path
MD [drive:]path

 

★ If necessary, MKDIR creates any intermediate directories in the path.

For example: Suppose \ a does not exist, then: mkdir \ a \ b and:

mkdir \ A
the chdir \ A
mkdir \ B
the same. If the extension is deactivated, the need to type mkdir \ a \ b \ c \ d.



2.rd (Remove Directory): delete a directory.
 
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
 
1) / S in addition to the directory itself, it will also delete all subdirectories and files in the specified directory. To remove a directory tree.

2) / Q Quiet mode without confirmation belt / S remove a directory tree.

 

Description:

⑴ only empty subdirectories (excluding files) can be deleted (unless you use the / S parameter).

⑵ root directory of the current directory and can not be deleted.

 

3. cd (Change Directory): Displays the current directory or changes the current directory.

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

 

1) Type CD drive: to display the current directory of the specified drive. Without parameters only type CD, the current drive and directory is displayed.

2) Use / D switch, in addition to changing the current directory to drive, you can also change the current drive.

 

(V) file manipulation commands

1. Create a new file

1)cd . > a.txt

    cd. represents change the current directory to the current directory, that did not mean change, and the output of this command does not have.
    ">" Indicates that the command output is written to the file, followed by a.txt, it means write to a.txt.
    And in this case there will be no command output, so we created an empty file.

2)copy nul a.txt
     nul表示空设备,从概念上讲,它不可见,存在于每个目录中,可以把它看成一个特殊的“文件”,它没有内容。
     此例子表示将空设备复制到a.txt,同样创建了没有内容的空文件。
 
3)echo a > a.txt
最常用的是echo命令,此例子表示把字母a和回车换行覆盖输出到a.txt(如果a.txt原来已有内容则覆盖掉原来的内容),如果追加内容,可以使用>>。
如echo b>>a.txt,表示把b和回车换行追加到文件末尾。
 

2. del :删除一个或数个文件。

DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

  • names:指定一个或多个文件或者目录列表。通配符可用来删除多个文件。如果指定了一个目录,该目录中的所有文件都会被删除。
  • /P 删除每一个文件之前提示确认。
  • /F 强制删除只读文件。
  • /S 删除所有子目录中的指定的文件。
  • /Q 安静模式。删除全局通配符时,不要求确认
  • /A 根据属性选择要删除的文件
    属性:R 只读文件、S 系统文件、H 隐藏文件、A 存档文件、I 无内容索引文件、L 重分析点、- 表示“否”的前缀

3. 查看文件

1) dir :显示目录中的文件和子目录列表

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  • [drive:][path][filename] 指定要列出的驱动器、目录和/或文件。
  • /A:显示具有指定属性的文件。
    属性:D 目录、R 只读文件、H 隐藏文件、A 准备存档的文件、S 系统文件、I 无内容索引文件、L 解析点、- 表示“否”的前缀
  • /B:使用空格式(没有标题信息或摘要)。
  • /C:在文件大小中显示千位数分隔符。这是默认值。用 /-C 来禁用分隔符显示。
  • /D:跟宽式相同,但文件是按栏分类列出的。
  • /L:用小写。
  • /N:新的长列表格式,其中文件名在最右边。
  • /O:用分类顺序列出文件。
    排列顺序:N 按名称(字母顺序)、S 按大小(从小到大)、E 按扩展名(字母顺序)、D 按日期/时间(从先到后)、G 组目录优先、- 反转顺序的前缀
  • /P:在每个信息屏幕后暂停。
  • /Q:显示文件所有者。
  • /R:显示文件的备用数据流。
  • /S:显示指定目录和所有子目录中的文件。
  • /T:控制显示或用来分类的时间字符域。
    时间段:C 创建时间、A 上次访问时间、W 上次写入的时间
  • /W:用宽列表格式,简要显示。
  • /X:显示为非 8.3 文件名产生的短名称。格式是 /N 的格式,短名称插在长名称前面。如果没有短名称,在其位置则显示空白。
  • /4:用四位数字显示年

(2) type:显示文本文件的内容。

TYPE [drive:][path]filename

 

4. 修改文件

(1) ren:重命名文件。

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.
请注意,您不能为目标文件指定新的驱动器或路径。

(2) copy:将一份或多份文件复制到另一个位置

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

  • source:指定要复制的文件。
  • /A:表示一个 ASCII 文本文件。
  • /B:表示一个二进位文件。
  • /D:允许解密要创建的目标文件
  • destination 为新文件指定目录和/或文件名。
  • /V:验证新文件写入是否正确。
  • /N:复制带有非 8dot3 名称的文件时,尽可能使用短文件名。
  • /Y:不使用确认是否要覆盖现有目标文件的提示。
  • /-Y:使用确认是否要覆盖现有目标文件的提示。
  • /Z:用可重新启动模式复制已联网的文件。
  • /L:如果源是符号链接,请将链接复制到目标而不是源链接指向的实际文件。

要附加文件,请为目标指定一个文件,为源文件指定数个文件(用通配符或 file1+file2+file3 格式)。

㈥通配符
 
* 匹配0到多个任意字符
? 匹配任意单个字符
[] 匹配括号中的1个字符
[!] 匹配不在括号中的一个字符, 例如: [!1-9]*
 
Windows 中有两种通配符:问号(?)匹配文件名中的任何一个字符,星号(*)匹配文件名中的零个或多个字符。
可以在一个命令中综合使用这些通配符以定位多个文件,或者在不记得文件的全名时找到该文件。
例如,假定当前目录中含有文件:date help help1 help2 help3 myprog.f myprog.o
 

另外,通配符在 Windows 的“搜索”中也可以使用。

 

㈦命令输入技巧

在 DOS 操作系统中,打错命令有两种情况:

1)打错命令,若未回车可用退格键或左方向键(←)抹去错误后重打,然后回车执行。

2)打错了命令,已经回车,可用功能键修改。

 

常用 DOS 功能键有:

 

实际上,我们更多时候会在 Windows 下修改,“命令行解释器”给我们提供了更方便的修改方法。首先,在未回车时输左方向键(←)并不会像 DOS 中那样删除前一个字符,只会移动光标,故只需把光标移到有错误的地方修改即可。并且,Windows 中可使用上方向键(↑)来遍历已经输过的命令。另外,“命令行解释器”还提供了强大的复制/粘贴功能。
 
举例示范:
假如上一个命令是“dir transitional.txt”,现在要输入“type transitional.txt”,有两种方法:
 
1)先按上方向键(↑)(或<F3>),屏幕显示:dir transitional.txt 。再按<Home>键,将光标移动到行首,按三次<Del>键,再输入 type ,即完成命令。
 
2)在窗口中点右键,选择“标记”,再用鼠标拉框选中上一个命令中的“transitional.txt”,按回车,就将文本“transitional.txt”复制到了剪贴板。然后输入“type”,空格,再点右键,选择“粘贴”,即完成命令。


要提高输入效率还得靠另一个功能键:<Tab> ,它能自动补完文件名。例如,假设当前目录中以字母 t 开头的只有 transitional.txt 和 trap.exe ,但你嫌 transitional.txt 这个名字太长,于是你输入“type”空格后,输入“t”,然后按<Tab> ,命令行解释器会自动补完后面的部分,变成“type transitional.txt”,如果再按<Tab>,就会在 transitional.txt 和 trap.exe 这两个文件名之间切换。
 
 
㈧常用命令

 

㈨内部命令

cd [/d] [drive:][directory]

del 删除命令行上指定的文件。可以指定一个或多个文件,可以使用通配符。

如果列出了一个目录,该目录中的所有文件都会被删除,尽管该目录不会删除(要删除目录,使用rd命令)

md foldername 创建一个新目录(同 mkdir)

rd [/s] [/q] path 删除目录
rd path 删除空目录
rd /s path 删除目录
rd /s /q path 删除目录,不提示

copy mydata.dat mydata.backup 将文件移动位置,可以在不同目录
copy mydata.dat e:\files\april2002data.dat

date /t 当前日期
time /t 当前时间

type [path]filename 将指定的文件写到标准输出

ver 显示计算机的Windows版本

dir %windir% /p 分页长列表
dir /w 按行列出名称
dir /d 按列列出名称
dir /ah 列出隐藏文件

start "" "path" 启动带有空格的文件

 
参考:https://www.jianshu.com/p/7ce7c8e4e5e9

Guess you like

Origin www.cnblogs.com/shihaiying/p/11845215.html