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

Windows 10命令提示符:如何在CMD中执行unzip、sed、cat及Ubuntu命令?

Hey there! Let's break down how to handle unzip, sed, cat operations in Windows 10 CMD, plus the best way to run your original Ubuntu terminal commands. I've got two solid approaches for you—using native Windows tools/alternatives, or leaning on WSL for a full Ubuntu environment that plays nice with Windows.

Option 1: Use Native Windows Tools & Command Alternatives

If you want to stick strictly to CMD without installing extra stuff, here's how to replicate those Linux commands:

cat Equivalent in CMD

Windows CMD has the type command that does almost exactly what cat does in Ubuntu:

  • Display the contents of a single file:
    type filename.txt
    
  • Concatenate multiple files into a new one:
    type file1.txt file2.txt > combined_output.txt
    

Just like cat, you can use >> to append to an existing file instead of overwriting it.

unzip Equivalent in CMD

Starting with Windows 10 version 1709, Microsoft added a native tar command that handles zip files perfectly:

  • Extract a zip archive to the current directory:
    tar -xf your_archive.zip
    

If you're on an older Win10 build, you can use the less flexible expand command:

expand your_archive.zip -F:* destination_folder

sed Equivalent in CMD

CMD doesn't have a native sed utility, but you've got two good workarounds:

  1. Call PowerShell from CMD:
    PowerShell has built-in string replacement that mimics sed's core functionality. Run this directly in CMD:

    powershell -Command "(Get-Content your_file.txt) -replace 'old_text', 'new_text' | Set-Content your_file.txt"
    

    This replaces all instances of old_text with new_text in your_file.txt, just like sed -i 's/old/new/g' your_file.txt in Ubuntu.

  2. Install GNU Sed for Windows:
    Grab a standalone binary of GNU Sed (the same one used in Ubuntu) from official GNU tools for Windows, add its folder to your system PATH, and then you can use sed exactly like you do in Ubuntu:

    sed -i 's/old_text/new_text/g' your_file.txt
    
Option 2: Run Original Ubuntu Commands Directly with WSL (Best for Full Compatibility)

If you want to run your exact Ubuntu terminal commands without any tweaks, WSL (Windows Subsystem for Linux) is the way to go—it lets you run a full Ubuntu environment right alongside Windows. Here's how to set it up:

  1. Enable WSL:
    Open CMD as an administrator, then run:

    wsl --install
    

    This automatically enables the WSL feature and installs the latest Ubuntu distro. If you're on an older Win10 build (pre-2004), run this instead:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    

    Then restart your computer to apply the changes.

  2. Set Up Ubuntu:
    After restarting, open the Start Menu, search for "Ubuntu", and launch it. Follow the prompts to create a Linux username and password (this is separate from your Windows account).

  3. Access Your Windows Files:
    Your Windows drives are mounted in WSL under /mnt/—so your C: drive is at /mnt/c/. To navigate to your Windows documents, for example:

    cd /mnt/c/YourWindowsUsername/Documents
    
  4. Run Your Original Ubuntu Commands:
    Now you can use unzip, sed, cat, and any other Ubuntu commands exactly as you did before. For example:

    unzip archive.zip
    sed -i 's/foo/bar/g' script.sh
    cat logfile.txt
    

    All your existing Linux scripts will work without modification—no need to rewrite anything for Windows.


内容的提问来源于stack exchange,提问作者Philipp M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:06:52