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 @ 2024-01-31 16:59  klchang  阅读(930)  评论(0编辑  收藏  举报