Files
tldr/pages.zh/windows/new-item.md

33 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 新建项目
> 创建一个新的文件、目录、符号链接或注册表项。
> 注意:此命令只能通过 PowerShell 使用。
> 更多信息:<https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-item>。
- 创建一个新的空文件(相当于 `touch`
`New-Item {{path\to\file}}`
- 创建一个新的目录:
`New-Item -ItemType Directory {{path\to\directory}}`
- 创建一个新的文本文件并写入指定内容:
`New-Item {{path\to\file}} -Value {{content}}`
- 在多个位置写入相同的文本文件:
`New-Item {{path\to\file1 , path\to\file2 , ...}} -Value {{content}}`
- 创建一个指向文件或目录的符号链接\硬链接\连接点:
`New-Item -ItemType {{SymbolicLink|HardLink|Junction}} -Path {{path\to\link_file}} -Target {{path\to\source_file_or_directory}}`
- 创建一个新的空注册表项(在 REG_SZ 中,使用 `New-ItemProperty``Set-ItemProperty` 来调整值类型):
`New-Item {{path\to\registry_key}}`
- 创建一个新的空注册表项并指定值:
`New-Item {{path\to\registry_key}} -Value {{value}}`