Windows 下 cat 和 touch 的等价命令

Linux 系统下,常用 cat 命令查看文本文件内容、touch 命令新建空白文件。Windows 系统往往也有这些需求,具体的等价命令,如下:

1.  Linux cat 命令

在 Windows CMD  中,Linux cat 命令的等价命令为 type 命令,具体示例,如下:

echo line from file1 > file1.txt
echo line from file2 > file2.txt
type file1.txt file2.txt > some_file.txt
type some_file.txt

运行结果,如下图所示

注,在 PowerShell 中,Linux cat 命令的等价命令也为 type 命令,不过没有合并文件的功能,即在 PowerShell 中,执行命令 “type file1.txt file2.txt > some_file.txt” 会报错。

2. Linux touch 命令

在 Windows CMD 中,使用如下命令,实现 Linux touch 命令新建空白文件。

type nul >> file.txt
# - or - 
copy nul file.txt

注,在 PowerShell 中,Linux touch 命令的等价命令为 New-Itemni

参考资料

[1] Windows: `Cat` Equivalent – CMD & PowerShell. https://www.shellhacks.com/windows-cat-equivalent-cmd-powershell/

[2] Windows: `Touch` Command – Equivalent. https://www.shellhacks.com/windows-touch-command-equivalent/

 

posted @   klchang  阅读(3299)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-01-31 Ubuntu 20.04 安装 CUDA Toolkit 的三种方式
点击右上角即可分享
微信分享提示