什么是命令行解释器(Command Line Interpreter)? 通常(Generally),所有现代程序都有图形用户界面 (GUI)(Graphical User Interface (GUI))。这意味着界面具有用户可以用来与系统交互的菜单和按钮。但是命令行解释器是一个只接受来自键盘的文本命令的程序。然后将这些命令执行到操作系统。用户从键盘输入的文本行被转换为操作系统可以理解的功能。这是命令行解释器的工作。
直到 1970 年代,命令行解释器才被广泛使用。后来,它们被具有图形用户界面(Graphical User Interface)的程序所取代。
命令行解释器在哪里使用?(Where are Command Line Interpreters used?)
人们的一个常见问题是,为什么今天有人会使用命令行解释器?我们现在有了带有GUI的应用程序,这些应用程序简化了我们与系统交互的方式。那么为什么要在CLI上输入命令呢?命令行解释器在今天仍然具有相关性的三个重要原因。让我们一一讨论原因。
- 使用命令行可以更快、更自动地完成某些操作。例如,当用户登录时关闭某些程序的命令或从文件夹复制相同格式文件的命令可以自动化。这将减少您身边的手动工作。因此,为了快速执行或自动执行某些操作,命令是从命令行解释器给出的。
- 图形应用程序非常易于使用。它不仅是交互式的,而且是不言自明的。下载应用程序后,会有一堆菜单/按钮等……它们将指导您在程序中进行任何操作。因此(Thus),新的和没有经验的用户总是更喜欢使用图形应用程序。使用命令行解释器并不那么简单。没有菜单。一切都需要输入。然而,某些有经验的用户使用命令行解释器。这主要是因为通过CLI,您可以直接访问操作系统中的功能。有经验的用户知道访问这些功能有多么强大。因此(Thus),他们使用CLI。
- 有时,系统上的GUI软件不是为支持运行或控制操作系统所需的命令而构建的。在这种情况下,用户别无选择,只能使用命令行界面。如果系统缺乏运行图形程序所需的资源,那么命令行界面(Command Line Interface)就派上用场了。
在某些情况下,使用命令行界面(Command Line Interface)比图形程序更有效。下面列出了使用CLI的主要目的。
- 在命令行解释器中,可以使用盲文系统(Braille system)显示指令。这对盲人用户很有帮助。他们不能独立使用图形应用程序,因为界面对他们来说不是用户友好的。
- 科学家、技术专家和工程师更喜欢命令解释器而不是图形界面。这是由于可以执行某些命令的速度和效率。
- 某些(Certain)计算机没有支持图形应用程序和程序顺利运行所需的资源。在这种情况下也可以使用命令行解释器。
- 键入命令可以比单击图形界面中的选项更快地完成。命令行解释器还为用户提供了GUI应用程序无法实现的范围广泛的命令和操作。
另请阅读:(Also Read:) 什么是设备驱动程序?(What is a Device Driver?)
在现代使用命令行解释器的实例有哪些?(What are some instances where command-line interpreters are used in the modern-day?)
曾经有一段时间,输入命令是与系统交互的唯一方式。然而,随着时间的推移,图形界面变得越来越流行。但是命令行解释器仍在使用中。浏览下面的列表,了解它们的使用位置。
- Windows 操作系统有一个名为Windows 命令提示符的 CLI。(Windows Command Prompt.)
- Junos 和Cisco IOS 路由器(Cisco IOS routers)的配置是使用命令行解释器完成的。
- 一些Linux系统也有CLI。它被称为Unix shell。
- Ruby和PHP有一个用于交互使用的命令 shell。PHP中的 shell称为PHP-CLI。
所有的命令行解释器都一样吗?(Are all command-line interpreters the same?)
我们已经看到,命令解释器只不过是一种仅使用基于文本的命令与系统交互的方式。虽然有几个命令行解释器,但它们都是一样的吗?不会。这是因为您在CLI(CLI)中键入的命令是基于您使用的编程语言的语法。因此(Thus),在一个系统上的CLI上运行的命令在其他系统中的运行方式可能不同。您可能必须根据操作系统的语法和该系统上的编程语言来修改命令。
了解语法和正确的命令很重要。例如,在一个平台上,命令扫描现在将指示系统扫描病毒。但是,在其他系统中可能不一定能识别相同的命令。有时,不同的OS/programming语言有类似的命令。它可能会导致系统执行类似命令会执行的操作,从而导致不良结果。
(Syntax)还必须考虑语法和大小写敏感性。如果您输入的命令语法错误,系统最终可能会误解该命令。结果是,要么没有执行预期的操作,要么发生了一些其他活动。
不同操作系统中的命令行解释器(Command Line interpreters in different operating systems)
要执行故障排除和系统修复等活动,Windows XP和Windows 2000中有一个称为故障恢复控制台(Recovery Console in Windows XP)的工具。这个工具也兼作命令行解释器。
MacOS 中的 CLI 称为终端。(Terminal.)
Windows操作系统有一个名为命令提示符的应用程序。(Command Prompt.)这是Windows中的主要(Windows)CLI。最新版本的Windows有另一个CLI - Windows PowerShell。此CLI比命令提示符(Command Prompt)更高级。两者都在新版本的Windows 操作系统(Windows OS)中可用。
某些应用程序同时具有CLI和图形界面。在这些应用程序中,CLI具有图形界面不支持的功能。CLI提供了额外的功能,因为它具有对应用程序文件的原始访问权限。
推荐:(Recommended:) 什么是服务包?(What is a Service Pack?)
Windows 10 中的命令提示符(The Command Prompt in Windows 10)
如果您知道命令提示符(Command Prompt)命令,故障排除会容易得多。命令提示符是(Command Prompt)Windows操作系统中CLI的名称。不可能或没有必要知道所有命令。在这里,我们汇总了一些重要命令的列表。
- Ping – 这是用于检查本地网络系统是否正常工作的命令。如果您想知道互联网是否存在实际问题或某些软件导致问题,请使用 Ping。您可以 ping 搜索引擎或远程服务器。如果您收到响应,则表示存在连接。
- IPConfig – 此命令用于在用户遇到网络问题时进行故障排除。当您运行该命令时,它会返回有关您的 PC 和本地网络的详细信息。显示不同网络连接的状态、正在使用的系统、正在使用的路由器的 IP 地址等详细信息。
- 帮助(Help)- 这可能是最有用和最常用的命令提示符(Command Prompt)命令。执行此命令将在命令提示符(Command Prompt)上显示所有命令的完整列表。如果您想了解有关列表中任何特定命令的更多信息,可以通过键入 -/?此命令将显示有关指定命令的详细信息。
- Dir - 用于浏览计算机上的文件系统。该命令将列出在您当前文件夹中找到的所有文件和文件夹。它也可以用作搜索工具。只需(Just)在命令中添加 /S 并输入您要查找的内容。
- Cls - 如果您的屏幕充满了太多命令,请运行此命令以清除屏幕。
- SFC——在这里,SFC代表系统文件检查器(System File Checker)。SFC/Scannow用于检查任何系统文件是否有错误。如果可以修复它们,那也可以。由于必须扫描整个系统,因此该命令可能需要一些时间。
- 任务列表 - 如果您想查看系统上当前处于活动状态的所有任务,您可以使用此命令。虽然此命令仅列出所有正在运行的任务,但您还可以通过将 -m 与该命令一起使用来获取其他信息。如果您发现一些不必要的任务,您可以使用命令Taskkill强制停止它们。
- Netstat – 这用于获取与您的 PC 所在网络相关的信息。显示以太网统计信息、IP 路由表、TCP连接、正在使用的端口等详细信息。
- Exit – 此命令用于退出命令提示符。
- Assoc – 这用于查看文件扩展名,甚至更改文件关联。如果您键入 assoc [.ext],其中 .ext 是文件扩展名,您将获得有关扩展名的信息。例如,如果输入的扩展名是 .png,它会告诉您它是一个图像文件。文件关联也可以更改。考虑示例 assoc .log = txt 文件。这将确保所有日志文件今后都被视为文本文件。
- 密码(Cipher)- 用于查看和更改文件和文件夹中的加密详细信息。您可以应用一些附加参数并加密您的文件或创建一组新的加密密钥。您还可以搜索系统上的加密文件。
概括(Summary)
- 命令行(Command Line)界面是一种通过基于文本的命令与系统交互的方式
- 每个操作系统都有其命令行界面。因此语法和命令因系统而异
- 尽管CLI曾经是主要的交互模式,但现在它已在很大程度上被图形界面所取代
- 但是,当在命令行界面上执行时,仍有某些操作更快、更高效。因此,它们仍在使用中
- 有经验的用户使用CLI自动执行命令或执行一些(CLI)GUI程序不支持的操作
- CLI 对盲人用户也很有用
- 命令的基本(Basic)知识将帮助您解决系统上的错误
What is a Command Line Interpreter?
What is a Command Line Interpreter? Generally, all modern programs have a Graphical User Interface (GUI). This means that the interface has menus and buttons that the users can use to interact with the system. But a command-line interpreter is a program that accepts only text commands from a keyboard. These commands are then executed to the operating system. The lines of text that the user enters from the keyboard are converted to functions that the OS can understand. This is the job of the command line interpreter.
Command-line interpreters were widely used until the 1970s. Later, they got replaced by programs with Graphical User Interface.
Where are Command Line Interpreters used?
One common question that people have is, why would anyone use a command-line interpreter today? We now have applications with GUI that have simplified the way we interact with systems. So why type out the commands on a CLI? There are three important reasons why command-line interpreters are still relevant today. Let us discuss the reasons one by one.
- Certain actions can be done more quickly and automatically using the command line. For instance, the command to shut down some programs when a user logs in or the command to copy files of the same format from a folder can be automated. This will reduce the manual work from your side. Thus for quick execution or to automate certain actions, commands are given from the command line interpreter.
- A graphical application is quite easy to use. It is not only interactive but also self-explanatory. Once you download the application, there are a bunch of menus/buttons, etc… that will guide you with any operation within the program. Thus, new, and inexperienced users always prefer using a graphical application. Using a command-line interpreter is not as simple. There are no menus. Everything needs to be typed out. Yet, certain experienced users use the command line interpreter. This is mainly because, with a CLI, you have direct access to functions in the operating system. Experienced users know how powerful it is to have access to these functions. Thus, they make use of the CLI.
- Sometimes, the GUI software on your system is not built to support the commands needed to run or control the operating system. At such times, the user has no option but to make use of the command-line interface. If a system lacks the resources needed to run a graphical program, then Command Line Interface comes handy.
In certain situations, it is more efficient to use Command Line Interface over a graphical program. The primary purposes of using a CLI are listed below.
- In command-line interpreters, it is possible to display the instructions using the Braille system. This is helpful for blind users. They cannot make use of graphical applications independently as the interface is not user friendly for them.
- Scientists, technical experts, and engineers prefer command interpreters over graphical interfaces. This is due to the speed and efficiency with which certain commands can be executed.
- Certain computers do not have the resources needed to support the smooth functioning of graphical applications and programs. Command-line interpreters can be used in such cases as well.
- Typing commands can be accomplished faster than clicking on the options in a graphical interface. A command-line interpreter also provides the user with a wide range of commands and operations that are not possible with a GUI application.
Also Read: What is a Device Driver?
What are some instances where command-line interpreters are used in the modern-day?
There was a time when typing out commands was the only way to interact with the system. However, with time, graphical interfaces became more popular. But command line interpreters are still in use. Go through the list below, to know where they are used.
- Windows OS has a CLI called Windows Command Prompt.
- The configuration of Junos and Cisco IOS routers is done using command-line interpreters.
- Some Linux systems also have the CLI. It is known as the Unix shell.
- Ruby and PHP have a command shell for interactive use. The shell in PHP is known as PHP-CLI.
Are all command-line interpreters the same?
We have seen that a command interpreter is nothing but a way to interact with the system with text-based commands only. While there are several command-line interpreters, are all of them alike? No. This is because the commands you type in the CLI are based on the syntax of the programming language you are using. Thus, a command that works on a CLI on one system may not work the same way in other systems. You may have to modify the command based on the syntax for the operating system and programming language on that system.
It is important to be aware of the syntax and the right commands. For instance, on one platform, the command scan now would direct the system o scan for viruses. However, the same command may not necessarily be recognized in other systems. Sometimes, a different OS/programming language has a similar command. It may lead to the system performing the action the similar command would do, leading to undesirable results.
Syntax and case sensitiveness must also be considered. If you enter a command with the wrong syntax, the system may end up misinterpreting the command. The result is, either the intended action is not performed, or some other activity takes place.
Command Line interpreters in different operating systems
To perform activities such as troubleshooting and system repair, there is a tool called Recovery Console in Windows XP and Windows 2000. This tool doubles up as the command line interpreter as well.
The CLI in MacOS is called Terminal.
Windows operating system has an application called Command Prompt. This is the primary CLI in Windows. The latest versions of Windows have another CLI – the Windows PowerShell. This CLI is more advanced than the Command Prompt. Both are available in the new version of the Windows OS.
Certain applications have both – a CLI and a graphical interface. In these applications, the CLI has features that are not supported by the graphical interface. The CLI provides extra features because it has raw access to application files.
Recommended: What is a Service Pack?
The Command Prompt in Windows 10
Troubleshooting would be much easier if you are aware of the Command Prompt commands. Command Prompt is the name given to the CLI in Windows operating system. It is not possible or necessary to know all the commands. Here we have put together a list of some of the important commands.
- Ping – This is a command used to check whether your local network system is working properly. If you want to know if there is an actual issue with the internet or some software causing the issue, use Ping. You can ping a search engine or your remote server. If you receive a response, it means that there is a connection.
- IPConfig – This command is used for troubleshooting when the user is facing network issues. When you run the command, it returns details about your PC and local network. Details such as the state of different network connections, the system in use, the IP address of the router in use, etc are displayed.
- Help – This is probably the most helpful and most used Command Prompt command. Executing this command will display the entire list of all commands on Command Prompt. If you want to know more about any particular command on the list, you can do so by typing – <command name> /? This command will display detailed information about the command specified.
- Dir – This is used to browse the file system on your computer. The command will list all the files and folders found in your current folder. It can also be used as a search tool. Just add an /S to the command and type what you are looking for.
- Cls – If you are screen is filled with too many commands, run this command to clear the screen.
- SFC – Here, SFC stands for System File Checker. SFC/Scannow is used to check if any system files have errors. If repairing them is possible, that is done as well. Since the entire system has to be scanned, this command may take some time.
- Tasklist – If you want to take a look at all the tasks that are currently active on your system, you may use this command. While this command only lists down all the tasks that are operating, you can also obtain additional information by using -m with the command. If you find some unnecessary tasks, you can force stop them by using the command Taskkill.
- Netstat – This is used to obtain information related to the network your PC is in. Details such as ethernet statistics, IP routing table, TCP connections, the ports in use, etc… are displayed.
- Exit – This command is used to exit the command prompt.
- Assoc – This is used to view the file extension and even change the file associations. If you type assoc [.ext] where .ext is the file extension, you will get information about the extension. For example, if the entered extension is .png, it will tell you that it is an image file. File associations can be changed too. Consider the example assoc .log = txt file. This will make sure that all log files are henceforth considered as text files.
- Cipher – It is used to view and change encryption details in your files and folders. You can apply some additional parameters and encrypt your files or create a new set of encryption keys. You can also search for encrypted files on your system.
Summary
- Command Line interface is a way to interact with the system through text-based commands
- Each OS will have its command-line interface. Thus the syntax and commands vary from system to system
- Although CLI was once the primary mode of interaction, it has now largely been replaced by graphical interfaces
- However, there are still certain operations that are quicker and more efficient when executed on a command-line interface. Thus, they are still in use
- Experienced users make use of CLI to automate commands or perform some operations that are not supported by GUI programs
- CLI is also useful for blind users
- Basic knowledge of commands would help you with troubleshooting errors on your system