首页 > 编程知识 正文

命令提示符快捷打开方式,怎么创建命令提示符的快捷方式

时间:2023-05-04 04:40:02 阅读:263204 作者:3469

命令提示符的快捷方式

Shortcuts are great for giving you quick access to files, apps, and folders. But did you know you can also use them to run Command Prompt commands?

快捷键非常适合使您快速访问文件,应用程序和文件夹。 但是您知道您也可以使用它们来运行命令提示符命令吗?

Windows gives you all kinds of ways to run command prompt commands. Sure, you could open a Command Prompt window and just type the command. You could also create yourself a batch script (or a bash script or PowerShell script if that’s your thing). And frankly, if you’re planning on running more than one command or you need anything complex, writing a script is a better option. But for simple commands, why not just create a double-clickable shortcut instead? Here’s how to do it.

Windows提供了各种方式来运行命令提示符命令。 当然,您可以打开“命令提示符”窗口,然后键入命令。 您也可以创建自己的批处理脚本 (如果这是您的话,则可以创建bash脚本或PowerShell脚本 )。 坦率地说,如果您打算运行多个命令或需要执行任何复杂的操作,那么编写脚本是一个更好的选择。 但是对于简单的命令,为什么不创建一个可双击的快捷方式呢? 这是操作方法。

Create a shortcut by right-clicking anywhere in File Explorer or your desktop and choosing New > Shortcut.

右键单击文件资源管理器或桌面上的任意位置,然后选择“新建”>“快捷方式”,以创建快捷方式。

In the Create Shortcut window, type your command using the following syntax:

在“创建快捷方式”窗口中,使用以下语法键入命令:

"C:WindowsSystem32cmd.exe" /k yourcommand

The first part (the part in quotes) just calls cmd.exe to open the Command Prompt. The switch /k tells Command Prompt to issue the command that follows, and then stay open so that you can view results or type followup commands. You can also use the /c switch instead /k (use only one of the switches) if you want the Command Prompt window to close after issuing the command. And of course, the yourcommand part is the actual command you want to run.

第一部分(引号中的部分)仅调用cmd.exe打开命令提示符。 开关/k告诉命令提示符发出随后的命令,然后保持打开状态,以便您可以查看结果或键入后续命令。 如果希望在发出命令后关闭命令提示符窗口,也可以使用/c开关代替/k (仅使用其中一个开关)。 当然, yourcommand部分是您要运行的实际命令。

For example, if you were creating a simple command to run the system file checker to find and fix problems with your system files, you’d type the following:

例如,如果要创建一个简单的命令来运行系统文件检查器以查找并修复系统文件问题,则可以键入以下内容:

"C:WindowsSystem32cmd.exe" /k sfc /scannow

When you’ve created the command you want to use, click “Next.”

创建要使用的命令后,请单击“下一步”。

Type a name for the shortcut and then click “Finish.”

输入快捷方式的名称,然后单击“完成”。

Now, you can run shortcut instead of firing up Command Prompt and typing the command manually each time.

现在,您可以运行快捷方式,而不是启动命令提示符并每次手动键入命令。

Another clever thing you can do is pipe the results of a command to a text file (or other program). For example, say we wanted to run the command ipconfig /all , have the results saved to a file named ipconfig.txt on your desktop, and have the Command Prompt window close after running the command. We could use the following to make that happen:

您可以做的另一件聪明的事情是将命令的结果传递到文本文件(或其他程序)中。 例如,假设我们要运行命令ipconfig /all ,将结果保存到桌面上名为ipconfig.txt的文件中,并在运行命令后关闭“命令提示符”窗口。 我们可以使用以下方法来实现:

"C:WindowsSystem32cmd.exe" /c ipconfig /all  > "c:usersusernameDesktopipconfig.txt"

If you use a single  >  for the piping command, Windows will overwrite the contents of the named file if the file already exists. If it doesn’t exist Windows will create the file. You can also use a double  >>  instead to have Windows append the new information from the command to an existing file instead of overwriting the file. This is useful if you want to keep a history of the results of a command.

如果对管道命令使用单个> ,则Windows将覆盖命名文件的内容(如果该文件已存在)。 如果不存在,Windows将创建该文件。 您也可以使用双>>来使Windows将命令中的新信息附加到现有文件中,而不是覆盖文件。 如果要保留命令结果的历史记录,这很有用。

Once you have your shortcut set up, it’s easy to run a command anytime you need to. And while you might still want to use a script for anything more complicated, running a command from a shortcut is great for simple one-off commands like scanning for corrupt system files, finding your IP address, shutting down Windows without installing updates, and more.

一旦设置了快捷方式,就可以在任何需要的时间轻松运行命令。 尽管您可能仍想使用脚本来处理更复杂的事情,但是从快捷方式运行命令非常适合简单的一次性命令,例如扫描损坏的系统文件 , 查找您的IP地址 , 关闭Windows而无需安装更新等。 。

翻译自: https://www.howtogeek.com/277403/how-to-run-command-prompt-commands-from-a-windows-shortcut/

命令提示符的快捷方式

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。