Win10 Powershell实现类似Linux指定tree命令展示深度
前言
今天又是远程上班的一天,愿NCP病毒早日过去……
用惯了Linux上的tree命令来展示目录结构,今天远程Win10上,需要通过目标结构写一些脚本,查看了下Powershell是默认有个tree命令的,但是不支持指定深度
所以,这篇文章主要是实现tree命令展示指定深度的目录结构功能
看了下Powershell官网的确有这个插件,描述是下边这shai er 的,大意是实现了命令行的通用功能 官网
PowerShell Community Extensions (PSCX) base module which implements a general purpose set of Cmdlets.
安装Powershell插件——Pscx
安装Pscx 3.2.2, 前边的命令是说安装这个插件的指定版本,后边的-Scope CurrentUser
表示此扩展仅作用于当前登录用户,-AllowClobber
是安装时提示这个模块会覆盖现有命令的错误,规避它使用此参数
Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber
出现如下提示,直接输入A,回车
PS D:\com-workspace\enterprise> Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber 不受信任的存储库 你正在从不受信任的存储库安装模块。如果你信任该存储库,请通过运行 Set-PSRepository cmdlet 更改其 InstallationPolicy 值。是否确实要从“PSGallery”安装模块? [Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): A
测试
Pscx扩展中有个命令叫做Show-Tree
,查看此命令的参数列表可以有哪些
PS D:\com-workspace\enterprise> get-help show-tree 名称 Show-Tree 摘要 Shows the specified path as a tree. 语法 Show-Tree [[-Path] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-Excl udeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>] Show-Tree [[-LiteralPath] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>] 说明 Shows the specified path as a tree. This works for any type of PowerShell provider and can be used to explore prov iders used for configuration like the WSMan provider. 相关链接 备注 若要查看示例,请键入: "get-help Show-Tree -examples". 有关详细信息,请键入: "get-help Show-Tree -detailed". 若要获取技术信息,请键入: "get-help Show-Tree -full".
使用Show-Tree 目录 -Depth 深度数
,就可以了(目录如果是当前,可以省略)
本文作者:东北小狐狸
本文链接:https://www.cnblogs.com/hellxz/p/12292047.html
版权声明:本作品采用自由转载-非商用-非衍生-保持署名 (CC BY-NC-ND 3.0)许可协议进行许可。
分类:
开发工具/Linux工具
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步