You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用touch命令创建.py文件?以及解决执行该命令时出现的“touch未被识别”错误

Hey there! Let's tackle your two questions one by one, since they're pretty common for folks switching between different OSes or getting started with command-line tools:

1. Creating a .py file with the touch command

If you're on a Linux or macOS system (or using a Unix-like shell on Windows like Git Bash/WSL), creating a blank Python file with touch is straightforward:

  • Run this command in your terminal:
    touch your_script_name.py
    
    Replace your_script_name.py with whatever name you want for your Python file (e.g., calculator.py, web_scraper.py). This creates an empty .py file in your current working directory.
  • Need multiple .py files at once? Just list them all:
    touch script1.py script2.py utils.py
    
2. Fixing the "'touch' is not recognized" error

That error pops up because Windows Command Prompt (CMD) doesn't include the touch command by default—it's a tool native to Unix-like systems. Here are three easy fixes:

  • Use Windows' built-in CMD alternative
    Instead of touch, run this command in CMD to create an empty .py file:

    type nul > your_script_name.py
    

    This does exactly the same thing as touch—creates a blank file with the .py extension.

  • Install a Unix-like shell (for frequent command-line use)
    If you find yourself needing Unix commands like touch often, install either:

    • Git Bash: Comes with Git for Windows, and includes a full set of Unix tools. Once installed, you can use touch just like you would on Linux/macOS.
    • Windows Subsystem for Linux (WSL): Lets you run a full Linux distribution directly on Windows. After setting it up, you'll have access to all standard Linux commands including touch.
  • Use PowerShell instead of CMD
    If you prefer PowerShell, use this command to create your .py file:

    New-Item -Name "your_script_name.py" -ItemType File
    

    Or use the shorter alias:

    ni your_script_name.py -Type File
    

内容的提问来源于stack exchange,提问作者Quickk Care

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 14:49:10