问题描述
在 Windows 机器上我收到此错误
On a windows machine I get this error
'touch' 不是内部或外部命令,也不是可运行的程序或批处理文件.
我正在遵循这些说明,这些说明似乎是特定于 linux 的,但在标准的 Windows 命令行上它不是这样工作的:
I was following these instructions which seem to be linux specific, but on a standard windows commandline it does not work like this:
touch index.html app.js style.css
是否有 Windows 等价于 linux/mac os/unix 世界的touch"命令?我是否需要手动创建这些文件(并修改它们以更改时间戳)才能实现此类命令?我正在使用节点,这似乎不太......节点式......
Is there a windows equivalent of the 'touch' command from the linux / mac os / unix world ? Do I need to create these files by hand (and modify them to change the timestamp) in order to implement this sort of command? I am working with node and that doesn't seem very ... node-ish...
推荐答案
在像 cmd 这样的 windows 命令行上替换 touch 命令的简单方法是:
An easy way to replace the touch command on a windows command line like cmd would be:
type nul > your_file.txt
这将在 your_file.txt
文件中创建 0 个字节.
This will create 0 bytes in the your_file.txt
file.
这也是在 Windows 批处理文件中使用的一个很好的解决方案.
This would also be a good solution to use in windows batch files.
另一种方法是使用 echo 命令:
Another way of doing it is by using the echo command:
echo.> your_file.txt
回声.- 将创建一个包含一个空行的文件.
echo. - will create a file with one empty line in it.
如果您需要保留文件的内容,请使用 >>
而不是 >
If you need to preserve the content of the file use >>
instead of >
> Creates a new file
>> Preserves content of the file
示例
type nul >> your_file.txt
您也可以使用 call 命令.
在不停止父批处理程序的情况下从另一个调用一个批处理程序.call 命令接受标签作为调用的目标.
示例:
call >> your_file.txt
---或者即使你不想让它变得困难,你也可以只安装 适用于 Linux 的 Windows 子系统 (WSL).然后,输入.
---or even if you don't want make it hard you can Just install Windows Subsystem for Linux (WSL). Then, type.
wsl touch
或
wsl touch textfilenametoedit.txt
不需要引号.
这篇关于在 windows 的命令行上创建一个空文件(如 linux touch 命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!