Wikipedia:格式手册 (命令行范例)
维基百科,自由的百科全书
维基百科格式指导 |
---|
格式手册 |
增补格式手册 |
特殊頁面指導 |
其他指导 |
如何编辑页面 |
技術指導 |
Command-line examples are used to specify the syntax of shell commands or programs as a user would type them into a terminal or command prompt. This page is intended to function as a style guide for writers and editors of articles related to Computer science on Wikipedia.
目录 |
[编辑] General guidelines
When providing command-line examples, it is necessary to maintain clarity and simplicity. Not only does this result in a more professional look, but it prevents the reader from becoming confused. The following guidelines are given to help establish what defines clear and simple examples.
- Command-line examples should be presented in a monospaced font. The initial presentation should use the Wikipedia method that involves prefixing commands with a space. Further references should be contained in <tt> (teletype) tags.
- Wikipedia is not a medium for the presentation of writers' personal preferences. As such, there should not be any reference to environment, date, working directory, user name, or host name unless absolutely necessary.
- Terminology: An option is a switch (something that modifies the general behavior of the command). A parameter is a specific value, such as a file or host name. The term argument is used to refer to any of the space-separated strings that follow a command name, including both options and parameters.
- When presenting arguments, care should be taken to maintain simplicity. Specifying them without explanation can confuse the reader.
- Wikipedia is not a substitute for manual pages. Articles should not document the entire list of options associated with a command unless there are very few such options or such descriptiveness is absolutely necessary.
- When specifying parameters, logical names should be used to refer to them. These names should be italicised and should not contain spaces, as spaces are used to separate multiple arguments on the command line. The following are some examples:
(prompt) command parameter-name
(prompt) command parameterName
(prompt) command parameter_name
(prompt) command parametername
- Consistency is important. Do not confuse the reader by using all four methods of naming parameters in the same article.
- Arguments that are not required and may be completely omitted should be enclosed within square brackets, [ and ].
- There are many ways of specifying repeating parameters; the following two are the most common:
(prompt) command parameter0 [.. parameterN]
(prompt) command [parameter ...]
[编辑] Platform-specific guidelines
[编辑] DOS
The most common disk operating system in use today is MS-DOS. As such, examples that might be specific to MS-DOS do not need to indicate this. However, if the examples are specific to a certain version of MS-DOS, then they should be indicated as such. If equivalents in other DOSes differ and are known, they should be provided.
The following additional guidelines should be followed for DOS command-line examples:
- The names of commands and programs should be provided in all upper-case letters.
- Standard MS-DOS-style options (of the form /C where C is some character) should also be upper-case, unless they are case sensitive.
- Program names should be contrasted against built-in command names by appending their appropriate file extension. If a specific program is not included with certain versions of MS-DOS (such as MOVE.EXE or EDIT.COM), then the versions for which it is known to be included should be indicated.
[编辑] Unix-like systems
- Most commands on Unix-like systems are actually references to executable files. Commands that are native to a shell (such as cd or history) should be indicated as such.
- The most common shell on Unix-like systems has varied greatly. As a result, shell-specific commands or utilities (such as the for loop or certain stream behaviors) should be avoided whenever possible.
- If a shell-specific sequence is required for proper explanation, then an example should be provided for both the ALGOL-like sequence of sh, ksh, and bash as well as one for the C-like syntax of csh and tcsh. This is not necessary if there is no difference in the syntax.
- The names of most commands on Unix-like systems are made up of all lower-case characters. However, due to the case-sensitive nature of the shell and operating environment, care should be taken to ensure that the capitalisation given matches that of the command or file name. Use of the wrong title template is recommended as well when necessary.
- Commands that normally require privileged access should be differentiated from those that do not require it. If a command does require priveleged access, then a disclaimer should be included indicating the risk of running commands with unrestricted priveleged access.
- In some cases, it is very likely the value of a parameter will contain some shell Meta-characters. In these cases, it may be wise to specify quoting in the example to prevent users from receiving errors that to them will seem strange and unrelated.
[编辑] Providing sample output
It may often be prudent to provide a sample of the output that a command is expected to generate. In these cases, the full command and all arguments as they were typed are given. The output of the command will therefore be specific to environment and other variables.
[编辑] Examples of usage
[编辑] DOS
- The DIR built-in command on DOS, which lists files and directories:
> DIR [options] [pattern ..]
- The program MOVE.EXE on MS-DOS (whose behavior had to be emulated prior to its introduction):
> MOVE.EXE source target
[编辑] 常规Unix
- 用Unix风格系统上的ls命令列出文件和目录:
$ ls [options] [file ..]
- 用mkfs命令创建新的文件系统,通常需要一定的权限:
# mkfs [-t fstype] [fs-options] device
$ wget [options] "URI"
[编辑] Shell特性
- sh/ksh/bash中内置if结构的语法异同:
$ if command ; then command ; .. ; fi
在csh/tcsh中:
% if (expression) then command ; .. ; endif
[编辑] 输出举例
- df命令的输出举例,列出了挂载的文件系统磁盘空间使用情况:
$ df -P Filesystem 512-blocks Used Available Capacity Mounted on /dev/hda2 39331760 7398904 29834768 20% /